如何打印完整的堆栈跟踪异常? [英] How to print full stack trace in exception?
本文介绍了如何打印完整的堆栈跟踪异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,在一个地方...
For example, in one place...
//---------------a
try
{
// some network call
}
catch(WebException we)
{
throw new MyCustomException("some message ....", we);
}
...而在另一个地方...
...and in another place...
//--------------b
try
{
// invoke code above
}
catch(MyCustomException we)
{
Debug.Writeline(we.stacktrace); // <----------------
}
我打印的stacktrace,它只从a开始到b,
它不包括来自WebException的内部stacktrace。
The stacktrace I print, it only start from a to b, it doesnt include the inner stacktrace from the WebException.
我如何打印所有的stacktrace ???
How can I print all the stacktrace???
推荐答案
我通常使用.ToString()方法来提供异常信息(包括文本中的内部栈跟踪)
I usually use the .ToString() method on exceptions to present the full exception information (including the inner stack trace) in text:
catch (MyCustomException ex)
{
Debug.Writeline(ex.ToString());
}
样本输出:
ConsoleApplication1.MyCustomException: some message .... ---> System.Exception: Oh noes!
at ConsoleApplication1.SomeObject.OtherMethod() in C:\ConsoleApplication1\SomeObject.cs:line 24
at ConsoleApplication1.SomeObject..ctor() in C:\ConsoleApplication1\SomeObject.cs:line 14
--- End of inner exception stack trace ---
at ConsoleApplication1.SomeObject..ctor() in C:\ConsoleApplication1\SomeObject.cs:line 18
at ConsoleApplication1.Program.DoSomething() in C:\ConsoleApplication1\Program.cs:line 23
at ConsoleApplication1.Program.Main(String[] args) in C:\ConsoleApplication1\Program.cs:line 13
这篇关于如何打印完整的堆栈跟踪异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文