views:

243

answers:

1

Is there a pragma or debugger attribute which will allow the debugger to not break on the throwing of a specific exception even though under the Debug >> Exceptions menu I've told it to break when any CLR Exceptions are throw?

In general while developing I like to have it break on exceptions while debugging so that I can immediately inspect them. Sometimes there are some isolated cases where it is known that this block of code occasionally throws exceptions and I've handled it in with a try-catch. See the answer to this question where the consensus was that try-catch is the most correct situation.

I'd like to be able to set an attribute on the method (something analogous to System.Diagnostics.DebuggerHiddenAttribute) which just ignores any exceptions thrown in the method.

BTW, I'm currently experiencing this in Visual Studio 2008, but I'm guessing there is either an answer for all versions or none.

+2  A: 

The direct answer can be found under Exceptions menu item of the Debug menu. This is a per solution/project setting. (Tools > Option > Debugging is a system-wide setting.) See the help topic Visual Studio Debugger, How to: Break When an Exception is Thrown at http://msdn.microsoft.com/en-us/library/d14azbfh.aspx for details. The Exceptions dialog allows you to set which exceptions are thrown or which exceptions break into the debugger.

I find I get more use out of the DebuggerStepThrough attribute.

In general, I leave throwing exceptions to the default (Debug > Exceptions user-unhandled checked and Thrown unchecked) and add the DebuggerStepThrough attribute for methods where I am not interested in stepping through nor am I interested in any exceptions being thrown within that method. I rarely use DebuggerHidden, and get more use with DebuggerNonUserCode in library code.

AMissico
`Debug` >> `Exceptions` is actually the menu that I've enabled it in (Tools was a typo). I want to break on all exceptions except this particular instance of an exception (e.g. `IOException` or some other common exception so I can't turn all of them off).It looks like DebuggerStepThroughAttribute is the answer I was looking for. I didn't think it would affect exceptions too. Thanks!
McKAMEY
Extra info: DebuggerStepThrough only supresses exceptions that are raised directly in that method. It won't suppress any exception raised lower in the call stack.
Steve Cooper