Why doesn't Visual Studio break on exceptions when debugging unit tests?

Viewed 11490

When I attempt to debug a unit test that fails because of an unhandled exception in my code, I expect Visual Studio to break on the unhandled exception so I can inspect the code and isolate the problem. Instead, the IDE instantly exits debug mode and the test is listed as "Failed", leaving me to consult the test result's stack trace to find the problem.

I've confirmed that the IDE is configured to break when any user-unhandled CLR exception is thrown. I can only get the expected behavior if I configure the IDE to break on all thrown exceptions. This, of course, makes normal debugging a PITA.

Am I out of luck?

8 Answers

I found a solution that works for me in a similar scenario.

If you notice that the debugger output is throwing handled exceptions you can note those exceptions.

Example

enter image description here

Take the ones you've just noted and open up the Exception SettingsException Settings

Alternatively you can hit Ctrl+Alt+E

From there you'll see a number of specific exceptions you can enable your IDE to break on.

For example: ArgumentNullException

enter image description here

Related