How to not break when user handled exception is thrown in visual studio 2019

Viewed 2745
Microsoft Visual Studio Enterprise 2019
Version 16.5.5
VisualStudio.16.Release/16.5.5+30104.148
Microsoft .NET Framework
Version 4.8.03752

I don't want visual studio to break in debug mode when such as below exceptions happened. The ones that i have handled via try catch. But i could not find a way even though I did extensive internet search

project details : asp.net web forms, .net 4.8 framework

enter image description here

3 Answers

How to not break when user handled exception is thrown in visual studio 2019

First, thanks to Jazimov for sharing the wonderful suggestion.

Actually, to stop breaking the specific exception(System.NullReferenceException) during Debug mode, you should try Jazimpv's suggestion.

Debug-->Windows-->Exception Settings-->Common Language Runtime Exceptions

uncheck System.Null.ReferenceException

enter image description here

This feature simply prevents exceptions from interrupting debugging, but does not block the occurrence of exceptions. Although it does not appear in the Code Editor, it will also be caught by the output window.

enter image description here

However, you can't get the most straightforward exception directly in the code editor without interrupting the debugging mode.

In order to get more detailed exception information, you can write this to show on Output Window:

  try
  {

     .........          
  }
  catch(Exception ex) 
  {
          Debug.WriteLine("=============================");
          Debug.WriteLine(ex.Message);
          Debug.WriteLine(ex.Source);
          Debug.WriteLine(ex.StackTrace);
          Debug.WriteLine("=============================");          
  }

enter image description here

I had a similar issue and found the fix here: Tell the debugger to continue on user-unhandled exceptions

Basically, in Exception Settings > Addition Actions column on Common Language Runtime Exceptions row, I right clicked and selected "Continue when unhandled in user code". i didn't see it break since.

You should be able to uncheck the checkbox next to "Break when this exception type is thrown" and that particular exception--when thrown--no longer should cause Visual Studio to break. Checking this checkbox does not generically prevent exceptions: You are preventing the debugger from breaking when this specific kind of exception is thrown. Notice that you also can restrict whether the debugger breaks for the particular exception to particular assemblies by checking boxes under the "Except when thrown" heading in the dialog you cited.

To view which exceptions are thrown by the debugger, go to Visual Studio's Debug | Windows | Exception Settings menu and expand the Common Language Runtime Exceptions branch:

enter image description here

Related