How to tell the debugger to ignore breaking on thrown exceptions?

南笙酒味 提交于 2019-12-17 12:48:10

问题


I have a TextBox in which I validate the input with a third party library. However, this library throws custom exceptions when the syntax is incorrect. This is not a real big deal, except for when you are debugging.

When debugging, since the text in the TextBox will always be initially wrong (I am still typing it), the debugger will stop after each letter until it is correct, which is really annoying as I validate with each letter.

How can I tell the debugger to not break at these custom exceptions?

P.S. I have already tried to filter the Debug -> Exceptions (added it in Common Language Runtime Exceptions), but this did not work for me. The debugger still stops at the line where the library is called.

P.P.S. Using Visual Studio 2010.

Answer:

In the end I was very close with my PS. It was a pretty silly mistake: I had a typo in the namespace. Thanks to Pop Catalin and Madhur Ahuja for pointing it out!


回答1:


There is an 'exceptions' window in Visual Studio ... try Ctrl-Alt-E when debugging and click on the 'Thrown' checkbox for the exception you want to stop on

You are looking for reverse of this: Visual Studio: How to break on handled exceptions?




回答2:


Debug + Exceptions, click the Add Button. Set the type to "Common Language Runtime Exceptions" and the Name to the full name of the custom exception, including the namespace name. You can now untick the Thrown box for this one, expand the node first if necessary.




回答3:


Assuming you want to break when the exception occurs unexpected you really should hide the method from the debugger using the [System.Diagnostics.DebuggerHidden] method.




回答4:


This worked for me: [DebuggerHidden]




回答5:


This is not a bug in the debugger, it was a intentional change. While the behavior is different and can be confusing, it had to be changed in Visual Studio 2010 to support several other scenarios including Silverlight debugging.

  1. Disable "break on user unhandled exceptions" for the exception types you you are encountering here (via Debug -> Exceptions)
  2. Disable "break on user unhandled exceptions" for all exceptions (via Debug -> Exceptions)

For more details please refer the link here.

Breaking on exceptions in VS2010



来源:https://stackoverflow.com/questions/4499473/how-to-tell-the-debugger-to-ignore-breaking-on-thrown-exceptions

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