How to: Set the Next Statement

This topic applies to:

Edition

Visual Basic

C#

C++

Web Developer

Express

Topic applies Topic applies Topic applies Topic applies

Standard

Topic applies Topic applies

Topic applies

Topic applies

Pro and Team

Topic applies Topic applies

Topic applies

Topic applies

Table legend:

Topic applies

Applies

Topic does not apply

Does not apply

Topic applies but command hidden by default

Command or commands hidden by default.

This feature is not available for T-SQL debugging.

In the Visual Studio debugger, you can move the execution point to set the next statement of code to be executed. A yellow arrowhead in the margin of a source or Disassembly window marks the location of the next statement to be executed. By moving this arrowhead, you can skip over a portion of code or return to a line previously executed. You can use this for situations such as skipping a section of code that contains a known bug.

Caution Setting the next statement causes the program counter to jump directly to the new location. Use this command with caution:

  • Instructions between the old and new execution points are not executed.

  • If you move the execution point backwards, intervening instructions are not undone.

  • Moving the next statement to another function or scope usually results in call-stack corruption, causing a run-time error or exception. If you try moving the next statement to another scope, the debugger opens a dialog box with a warning and gives you a chance to cancel the operation. In Visual Basic, you cannot move the next statement to another scope or function.

  • In native C++, if you have runtime checks enabled, setting the next statement can cause an exception to be thrown when execution reaches the end of the method.

  • When Edit and Continue is enabled, Set Next Statement will fail if you have made edits that Edit and Continue cannot remap immediately. This can occur, for example, if you have edited code inside a catch block. When this happens you will see an error message that looks like this: "Unable to set the next statement to this location. Operation not supported. Unknown error:error number"

Note In managed code, you cannot move the next statement under the following conditions:

  • The next statement is in a different method than the current statement.

  • Debugging was started via Just-In-Time debugging.

  • A callstack unwind is in progress.

  • A System.StackOverflowException or System.Threading.ThreadAbortException exception has been thrown.

You cannot set the next statement while your application is actively running. To set the next statement, the debugger must be in break mode. For more information, see Breaking Execution.

Note

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

To set the next statement to execute

  • In a source window, click the yellow arrowhead and drag it to a location where you want to set the next statement (in the same source file), or

  • In a source window, right-click on the statement you want to execute next and choose Set Next Statement from the shortcut menu.

  • In the Disassembly window, right-click the assembly-language instruction that you want to execute next and choose Set Next Statement from the shortcut menu.

See Also

Concepts

Execution Control