Share via


Debugging Exceptions

The debugger writes exception messages to the Output window. You can choose whether or not the program should halt or continue processing.

For Stop If Not Handled, the debugger writes a message to the Output window when an exception occurs, but does not halt the program unless the exception handler fails to handle the exception. At that point it is too late to fix the problem or examine the source code to see where the exception occurred because the program is already past the point where the exception occurred and is executing in the exception handler.

For Stop Always, the debugger stops the program and notifies you immediately when an exception occurs, before any handler code is invoked. You can look at the source window to see where the exception occurred, use the Watch and Variables windows and QuickWatch to see variable contents, and attempt to fix the exception yourself by modifying the variable contents. When you continue the program after the exception, a dialog box asks if you want to pass the exception back to the program’s exception handlers. If you fixed the problem, click No. Otherwise, click Yes, and the exception handler is invoked. If the exception handler cannot fix the problem, the debugger halts the program and notifies you as if the exception were Stop If Not Handled.

To set how the debugger handles exceptions

  1. From the Debug menu, click Exceptions.

    The Exceptions dialog box opens.

  2. Choose Stop Always or Stop If Not Handled for each exception type that can occur in your program.

The Exceptions list box in the Exceptions dialog box contains a default list of system exceptions. The information is saved in the project.DSW file, which persists with the project. If an exception is not included in this list, the debugger treats it as a Stop If Not Handled exception.

To add a new exception to the Exceptions list box

  1. From the Debug menu, click Exceptions.

    The Exceptions dialog box appears.

  2. In the Number box, type the exception number for the user-defined exception.

  3. Optionally, type the name of the exception in the Name box.

  4. Optionally, under Action, select the Stop Always or Stop If Not Handled option.

  5. Click Add.

  6. Click OK.

To change an exception parameter

  1. From the Debug menu, click Exceptions.

    The Exceptions dialog box appears.

  2. In the Exceptions list box, select the exception.

  3. Change any parameter, such as the name or the action.

  4. Click Change.

  5. Click OK.

To remove an exception from the Exceptions list box

  1. From the Debug menu, click Exceptions.

    The Exceptions dialog box appears.

  2. In the Exceptions list box, select the exception.

  3. Click Remove.

    When you delete an exception from the Exceptions list box, its action reverts to Stop If Not Handled.

  4. Click OK.

To restore all default system exceptions to the Exceptions list box

  1. From the Debug menu, click Exceptions.

    The Exceptions dialog box appears.

  2. Click Reset.

    All default system exceptions are restored to the Exceptions list box without disturbing any of the user-defined exceptions that have been added.

  3. Click OK.