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?
Tell the debugger to break when an exception is thrownIn the Exception Settings window (Debug > Windows > Exception Settings), expand the node for a category of exceptions, such as Common Language Runtime Exceptions. Then select the check box for a specific exception within that category, such as System.
The reason why is that your exceptions are not unhandled. The unit testing framework is handling the exceptions under the hood and converting them to failures.
What you need to do instead is to break on thrown exceptions. If you combine this with enabling "Just My Code" (on by default) you should get the behavior you are expecting. Visual Studio will only break when exceptions thrown by your code occur.
For me I am using VS 2010 and 2015, Go to: Tools, Options, Debugging, General: you need to make sure the "Enable Just My Code" and "Enable the exception assistant" should be checked.
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