#875 – Looking at the Call Stack after Catching an Exception
June 27, 2013 1 Comment
After an exception is thrown, it bubbles up the call stack until a handler that can handle the exception is found. If you set a breakpoint in an exception handler, you can then use the debugger in Visual Studio to examine the call stack, as it existed at the time that the exception was thrown.
In the example below, we’ve hit a breakpoint that we set in an exception handler. If we examine the Exception variable passed to the handler, we see that an exception of type ArgumentException has been thrown.
Notice that we can also look at the StackTrace property in the debugger. It contains text describing the call stack at the time that the exception was thrown. You can click on the magnifying glass icon to see the stack trace formatted in a way that’s easier to read.
In the example, we see that Dog.Bark threw the exception.