Partager via


Using Breakpoints

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Breakpoints can be used to halt an application at a specific point in the program code. When the application reaches the breakpoint, execution halts, and you can open a variable window (see Using Variable Windows) to determine the value of variables and expressions in your application. If your application is not behaving the way you planned, it is possible that one variable is being incorrectly set.

When the application reaches the breakpoint, you can single-step through the statements that follow the breakpoint to find out the value of the variable before it receives a value and its new value when it is set.

Setting a Breakpoint

Workflow Designer supports setting breakpoints in an activity in the workflow.

To set a breakpoint in Workflow Designer

  1. In Solution Explorer, open SpeechWorkflow1.cs.

    Workflow Designer appears, displaying the workflow for the application.

  2. In Workflow Designer, select movieAttendance.

  3. Right-click movieAttendance, click Breakpoint, and then select Insert Breakpoint.

You can also set breakpoints in individual statements in the code window. This provides the ability to fine-tune the statement on which you want the debugger to break.

To set a breakpoint in the code window

  1. In Solution Explorer, open VoiceResponseWorkflow1.cs.

    Workflow Designer appears, displaying the workflow for the application.

  2. In Visual Studio 2005, click Code on the View menu.

    Tip

    You can switch from the designer view to the code view by pressing F7 and from the code view to the designer view by pressing SHIFT+F7.

  3. Locate the movieAttendance_Executing method in SpeechWorkflow1.cs.

  4. Place the cursor at the beginning of the first statement in movieAttendance_Executing.

  5. Right-click Breakpoint, and then click Insert Breakpoint.

After you have set a breakpoint in the code window, start the application in the debugger and respond to the prompts. When execution reaches the movieAttendance_Executing method, the debugger halts the application. At this point, the Autos window (see Using Variable Windows) shows that the moviesPerYear variable is null. Single-step through the application by pressing F10 to see moviesPerYear change to the value that the application recognized.

Setting the Debugger to Break on Exceptions

You can also set the debugger to break when an exception is thrown, which can help you understand the root cause of a problem.

To set exception options in the debugger

  1. In Visual Studio 2005, click Exceptions on the Debug menu.

  2. On the Exceptions property page, expand the areas of interest, which include:

    • C++ Exceptions
    • Common Language Runtime Exceptions
    • Managed Debugging Assistants
    • Native Run-Time Checks
    • Win32 Exceptions
  3. Identify the exceptions on which you want the debugger to break, and then select the Thrown check box for each.