Did you know… You can break the debugger without using Breakpoints? – #313

If you are using VB, you can add the keyword Stop in your code to suspend execution. The Stop statement is the equivalent to adding a breakpoint. Sometimes it is just faster to type “Stop” than it is to remember to hit F9 or reach for the mouse.

VB Stop example

If you are using C#, you can use the Debugger.Break() method in your code, provided you are using the System.Diagnostics namespace.

C# Debugger.Break() example

Technorati Tags: VS2005Tip,VS2008Tip

Comments (8)
  1. rprimrose says:

    I found Debugger.Break() really helpful when I needed to debug a Windows Service application as it was starting up. Sometimes it was too late to start the service then attach the debugger.

  2. santiiiii says:

    You can also break with "debugger" in javascript.

  3. GregM says:

    In C++, it’s _CrtDbgBreak() (_DEBUG only), or DebugBreak(), or _asm { INT 3 } (x86 only).

    Rory, see also Image File Execution Options (http://blogs.msdn.com/greggm/archive/2005/02/21/377663.aspx for example) (no, that’s not me).

  4. Morten says:

    Easier than pressing F9 ??? Give me a break! This is ugly and messy.

  5. Horatio Nelson says:

    … and then move your code to production and scratch your head while you try to figure out why your web app is crashing….

  6. DarthObiwan says:

    Another great one is Debugger.Attach(). This is useful when you are working on managed code hosted in an unmanaged application. Instead of doing the whole "Attach to Process" it just prompts you to attach itself.

  7. Richard says:

    "Easier than pressing F9?"

    Sometimes the code you want to debug is launched by someone else and you can’t easily launch it in the debugger yourself.  So you put that in your code and you’ll be prompted to JIT debug the code.

Comments are closed.

Skip to main content