How to evaluate raw exception properties in a direct window

I have an unhandled exception that invokes the Exception Assistant dialog box.

When I click "View Details ...", the exception itself has some values ​​in the user object model that will not be evaluated in the property grid, but I know that I can evaluate it in the next window. (In this case, the property grid will not allow me to go into the collection, but there may be other cases)

Without changing the code to add a try block , how can I go to the immediate window and evaluate the expressions in the thrown exception?

The answer will probably be some kind of magic that I just don't know yet, for example: this.CurrentException or

something involving System.Diagnostics.StackFrame or who knows. Something smart.

There is a way to navigate to it using the debugger stream, but it is rather complicated. If you can take it and make it simple with a wrapper, which could be a solution.

+7
debugging c # exception visual-studio-2010 immediate-window
source share
3 answers

Have you tried disabling the debugger when an exception is thrown, and not just when the user is not being processed?

To do this, go to the main menu of VS2010 and select the "Debug" menu. Then select "Exceptions ..."

This will cause a dialog like: Debug -> Exceptions .. menu

Select the Cast column

Now that you have selected the exception, you can evaluate the local variables in the Immediate window.

On the Locals tab, I see the $ exception variable: Local variables contains $ exception

I can use the $ exception variable in the immediate window: Immediate Window accessing $ exception

Update: I also recommend using the Exception Breaker Visual Studio Extension for easy switching of exception handling, which allows you to enable or disable the switching of exception handling from instead of the Debug toolbar.

+11
source share

I do not know about Visual Studio 2010, but in Visual Studio 2012, when an unhandled exception occurs, it appears in the Locals window with the name $exception .

+1
source share

there is a property that will not be evaluated in the property grid

If the property cannot be evaluated, the debugger will not help you, as you saw; therefore, a direct window will just do the same.

I had an invalid property so that it throws an exception in VS2010 and causes the debugger to crash when trying to evaluate it. The nulls returned from the properties were not pleasant for the debugger.

I recommend that you go old school to the problem and put Trace.Write in the property and elsewhere and keep track of the record reports in the exit window.

How to track and debug in Visual C #

0
source share

All Articles