Can I get Visual Studio to ignore a specific *instance* of an exception?

孤街醉人 提交于 2019-12-06 04:35:55

As others have mentioned, if an exception is truly caught and handled inside 3rd party code (where the debugger's definition of "3rd party code" is code that is in an assembly which is non-optimized AND we don't have .pdbs for), then to avoid the debugger from stopping on it, you simply need to go to Tools->Options->Debugging->General and enable "Just My Code".

If the code in question is not 3rd party code, you can add a DebuggerNonUserCode attribute to it, to control whether the debugger will break on an exception in the decorated method (again, assuming "Just My Code" is enabled).

In VS "15" Preview 5, you can actually disable breaking on an exception when it's thrown inside a specific module, but that's not available in VS2015.

Another option to workaround this quickly, is to use OzCode which has a ToolBar button for toggling "Break on All CLR Exceptions". This is a really quick way of enabling/disabling all exceptions, which you can toggle before you know the annoying NullReferenceException is about to occur.

Disclaimer: I'm co-creator of the tool I just mentioned.

If I understand you correctly, you don't want your code to stop being executed after a certain exception which occurs when you throw the exception. If you want to do this just put your try and catch block over that code and don't use the throw statement at all

         try
     { string strX  = textbox.Text
       int x = Convert.ToInt32(strX);
     }
    catch (FormatException){}
    ...rest of code

If you put a throw statement it would exit the block of code it is in

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