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.
With a solution open in Visual Studio, use Debug > Windows > Exception Settings to open the Exception Settings window. Provide handlers that respond to the most important exceptions. If you need to know how to add handlers for exceptions, see Fix bugs by writing better C# code.
An unhandled exception occurs when the application code does not properly handle exceptions. For example, When you try to open a file on disk, it is a common problem for the file to not exist. The . NET Framework will then throw a FileNotFoundException.
Note: you can uncheck Break when this exception type is thrown directly in the exception handler and continue debugging (press F5 ). Visual Studio will add this exception type to the Exception settings and will remember that it shouldn't break on this exception again.
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:
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:
I'm able to use the "$exception" variable in the immediate window:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With