.Net Meanderings

Richard Blewett's wanderings around .NET

Please read my disclaimer. Subscribe to my RSS feed

More Wonderful System.Diagnostic Goodness

One thing I missed in my eulogy to the System.Diagnostic namespace was the fact that you can capture the whole collection of stack frames. So what I hear you cry. Well if you look at the System.Exception class you see that it has a StackTrace member, but that is simply a string representation of the stack trace, it does not give you access to the actual stack frames. Well I was a bit saddened by this, and so was very happy to find out that even from an exception (that can be caught at any point in the call stack) that you can get at the full set of stack frames for the place where the exception was thrown.

Here is the code to do it - very simple as you can see, simply uses a specialized constructor of the StackTrace class.

try 
{ 
	// protected stuff here
} 
catch( Exception e ) 
{ 
	StackTrace st = new StackTrace(e); 
}

02/20/2004 2:15 AM | Comments [1849] | #stackframe #.NET #Diagnostics

Content © 2003 Richard Blewett | Subscribe to my RSS feed.

Powered by BlogX