C#相当于Java的Exception.printStackTrace()? [英] C# equivalent to Java's Exception.printStackTrace()?

查看:165
本文介绍了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());

从<一个href="http://msdn.microsoft.com/en-us/library/system.exception.tostring.aspx">http://msdn.microsoft.com/en-us/library/system.exception.tostring.aspx:

的ToString的默认实现获取抛出当前异常的消息,调用toString对内部异常的结果,并呼吁Environment.StackTrace的结果类的名称。如果任何这些部件的为空时,其值不包括在返回字符串中。

The default implementation of ToString obtains the name of the class that threw the current exception, the message, the result of calling ToString on the inner exception, and the result of calling Environment.StackTrace. If any of these members is null, its value is not included in the returned string.

请注意,在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()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆