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

牧云@^-^@ 提交于 2020-06-29 04:05:14

问题


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


回答1:


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:




回答2:


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

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.

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("=============================");          
  }



来源:https://stackoverflow.com/questions/61844267/how-to-not-break-when-user-handled-exception-is-thrown-in-visual-studio-2019

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!