.NET Tips and Tricks

Blog archive

Stop Debugging Code that Works

We all have utility methods that just work. But if you're in Debug mode and stepping through your code (and you forget to shift from using F10 to F11), you end up having to step through your utility method.

Of course, once you're in the method, you can use F7 to step out of the method and onto the statement following the statement that called your utility method. But it would be much better to just not step into the method at all.

That's easily done: just add the System.Diagnostics.DebuggerStepThrough attribute to your method. The next time you're stepping through your code, Visual Studio will just step over your method. Just remember to take the attribute off if you want to put a breakpoint in your utility method: Visual Studio takes this attribute very seriously and ignores breakpoints inside methods decorated with DebuggerStepThrough.

Posted by Peter Vogel on 01/31/2013 at 1:16 PM


comments powered by Disqus

Reader Comments:

Wed, Mar 6, 2013 Mattias

Good idea, but if you get an exception, even if it is caught, the debugger will stop. Why is it impossible to say that only stop at exceptions if inside code that is debugged?

Add Your Comments Now:

Your Name:(optional)
Your Email:(optional)
Your Location:(optional)
Comment:
Please type the letters/numbers you see above

.NET Insight

Sign up for our newsletter.

I agree to this site's Privacy Policy.