Debugging Exceptions

The debugger writes exception messages to the Output window. Use Exceptions on the Debug menu to specify what happens when an exception occurs while you are debugging a program. You can choose one of two actions when an exception occurs.

Stop if not handled specifies that 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. If an exception is handled, the program has passed the exception already and is executing the code in the handler. After execution has passed to the exception handler, it is too late to fix the problem or examine the source code to see where the exception occurred.

Stop always specifies that the debugger stops execution immediately where an exception occurs and notifies you before any handler code is invoked. This option gives you the opportunity to look at the source window to see where the exception occurred and use QuickWatch and the Watch and Variables windows to examine contents of variables. You may be able to fix the exception by modifying the contents of variables. When you continue the program after the exception, a dialog box asks if you want to pass the exception back to the program exception handlers. If you fixed the problem, choose No. Otherwise, choose Yes to execute the exception handler. 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. On the Debug menu, choose Exceptions.
  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. For each Windows CE platform, system exceptions are defined with the prefix of EXCEPTION in the Winbase.h file corresponding to the platform. The Exceptions dialog box settings are saved with the workspace and available for all projects in the workspace. 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. On the Debug menu, choose 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. Choose Add.

To change an exception parameter

  1. From the Debug menu, choose Exceptions.
  2. In the Exceptions list box, select the exception.
  3. Change any parameter, such as the name or the action.
  4. Choose Change.

To remove an exception from the Exceptions list box

  1. From the Debug menu, choose Exceptions.

    The Exceptions dialog box appears.

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

  3. Choose Remove.

    When you delete an exception from the Exceptions list box, its action reverts to Stop if not handled.

To restore all default system exceptions to the Exceptions list box

  1. From the Debug menu, choose Exceptions.

    The Exceptions dialog box appears.

  2. Choose Reset.

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