Persuade Visual studio not to break on unhandled exceptions

Viewed 108

I want to run some code in debug mode. I do NOT want VS to break on any exceptions. My attempts to persuade it not to are failing. In particular, I unchecked every box under "Break When Thrown" in the "Exception Settings" window. What else do I need to do?

DoNotBreakOnExceptions

2 Answers

According to this documentation we can know that try-catch or try-catch-finally blocks are used to handle thrown exceptions. You can use try-catch to handle the thrown exceptions like this:

try  
    {  
        throw new InvalidOperationException();  
}  
catch (Exception e)  
    {  
        Console.WriteLine("Cannot determine location type from provided inputs.");  
}  

Refer to this link we can know that uncheck the exceptions in Exception Setting just work for handled exception.

If you checked the exceptions in Exception Setting, the handled exception will also throw an exception and break the debug.

Uncheck or check exceptions in Exception Setting is invalid if you just throw an exception without handling it.

Unless you want to go for a try-catch solution. Try this:

In Debug->Exceptions dialog, uncheck the check box under the User-Unhandled column for whatever exception type you wish to eliminate, for example: Common Language Runtime Exceptions, and VS will stop breaking on these exceptions.

Related