本文介绍了C#相当于Java的Exception.printStackTrace()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一个C#等效方法Java的 Exception.printStackTrace()
或做我必须写自己的东西,通过InnerExceptions工作我的方式?
Is there a C# equivalent method to Java's Exception.printStackTrace()
or do I have to write something myself, working my way through the InnerExceptions?
推荐答案
试试这个:
Console.WriteLine(ex.ToString());
从http://msdn.microsoft.com/en-us/library/system.exception.tostring.aspx:
的ToString的默认实现获取抛出当前异常的消息,调用toString对内部异常的结果,并呼吁Environment.StackTrace的结果类的名称。如果任何这些部件的为空时,其值不包括在返回字符串中。
请注意,在C调用上述$ C $为的ToString
不是必需的,因为是一个重载需要 System.Object的
键,通话的ToString
直接
Note that in the above code the call to ToString
isn't required as there's an overload that takes System.Object
and calls ToString
directly.
这篇关于C#相当于Java的Exception.printStackTrace()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!