Question

I have an unhandled exception that causes the Exception Assistant dialog box to appear.

When I click on View Detail..., the exception itself has some values in it's custom object model that will not evaluate in the property grid, but I know I can evaluate it in the immediate window. (In this case the property grid won't let me drill down into a collection, but there can be other cases)

Without altering the code to add a try block, how can I go to the immediate window and evaluate expressions on the unhanded exception?

The answer will probably be some magic that I just don't know yet, like ?this.CurrentException or

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

There is a way to navigate to it using the debugger thread, but that's quite complicated. If you can take that and make it simple with a wrapper that might be a solution.

Was it helpful?

Solution

Did you try setting the debugger to break when the exception is thrown instead of just when it is User-unhandled?

To do this go to VS2010 main menu and select the 'Debug' menu Next select 'Exceptions...'

That will bring up a dialog like: Debug - loading= Exceptions.. menu">

Select the Thrown column

Now when your exception is thrown and you should be able to evaluate your local variables in the Immediate window.

In the Locals tab I can see the $exception variable: Local variables contains $exception

I'm able to use the "$exception" variable in the immediate window: Immediate Window accessing $exception

Update: Also for easy toggling of Exception handling I recommend using the Exception Breaker Visual Studio Extension, which allows you to toggle break on exception handling on and off from the tool bar instead of having to drill into the Debug menu.

OTHER TIPS

I don't know about Visual Studio 2010 but in Visual Studio 2012 when an unhandled exception occurs it's shown in the Locals window with the name $exception.

there is a property that will not evaluate in the property grid

If the property can't be evaluated, the debugger won't help you as you have seen; hence the immediate window would just do the same.

I had a invalid property such that it would throw an exception in VS2010 and cause the debugger to crash when I attempted to evaluate it. Nulls being returned from properties were not nice to the debugger.

I recommend that you go old school on the issue and put Trace.Write within the property and elsewhere and monitor the write reports in the output window instead.

How to trace and debug in Visual C#

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top