24

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.

For the non-believers

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!

Arcturus
  • 26,677
  • 10
  • 92
  • 107

5 Answers5

19

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?

Community
  • 1
  • 1
Madhur Ahuja
  • 22,211
  • 14
  • 71
  • 124
13

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.

bluish
  • 26,356
  • 27
  • 122
  • 180
user2381484
  • 131
  • 1
  • 2
  • 1
    There seems to be a bug with this approach in MSVS 2015 http://stackoverflow.com/questions/39382551 – crokusek Sep 08 '16 at 23:35
9

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.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
4

This worked for me: [DebuggerHidden]

Colonel Panic
  • 132,665
  • 89
  • 401
  • 465
  • 10
    Doesn't work, because it stops debugger on one level up in callstack from the method with [DebuggerHidden]. It may work for event handlers though. – Alex Klaus Nov 25 '13 at 23:46
  • @Klaus, agree, I'm not alone: http://stackoverflow.com/questions/39382551 – crokusek Sep 08 '16 at 23:47
0

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

Karthik
  • 187
  • 3
  • 11
  • That change really sucks, because I *want* to break on *unhandled* exceptions, but these exceptions are definitely handled. – BrainSlugs83 Aug 05 '20 at 22:12