2010年6月26日 星期六

[.NET] StackTrace with Exception

When a programmer develop .NET, he can use Exception.StatckTrace to get stack trace information.

Represents a stack trace, which is an ordered collection of one or more stack frames.

MSDN Remark has some information:

StackTrace information will be most informative with Debug build configurations. By default, Debug builds include debug symbols, while Release builds do not. The debug symbols contain most of the file, method name, line number, and column information used in constructing StackFrame and StackTrace objects.

using System;
class Orz
{
public static void Main()
{
try
{
XD();
}
catch( Exception e )
{
Console.WriteLine( "System.Exception stack trace = \n{0}", e.StackTrace );
}
}
static void XD()
{
throw new Exception( "XD() has some error" );
}
}


Output:
System.Exception stack trace =
at Orz.XD()
at Orz.Main()

沒有留言:

張貼留言

Hello