Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to evaluate unhandled exception properties in immediate window

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.

like image 885
toddmo Avatar asked Nov 06 '13 22:11

toddmo


People also ask

How do I fix unhandled exception in Visual Studio?

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.

What happens when an unhandled exception occurs?

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.

How do I make Visual Studio not stop on exception?

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.


1 Answers

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 -> 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.

like image 152
Chad Dienhart Avatar answered Oct 31 '22 08:10

Chad Dienhart