This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!
Handling Exceptions
An exception is an abnormal situation that happens while a program is running. Exceptions are often indications of problems that you need to debug. The Visual Studio debugger recognizes many types of exceptions. These include C++ exceptions, NGWS runtime exceptions, Win32 exceptions, and C Run-time Errors. Some types of exceptions, such as C++ exceptions, have handlers — pieces of code that are designed to respond to an exception when it occurs, giving the program a chance to recover from the abnormal situation. C runtime errors do not have handlers.
When an exception occurs, the debugger writes an exception messages to the Output window. The debugger can also break execution of the program when an exception occurs, giving you a chance to debug it. You can choose whether or not you want the debugger to break on a given type of exception or category of exceptions.
To change how the debugger handles an exception or category of exceptions
- From the Debug menu, click Exceptions.
The Exceptions dialog box opens.
- In the Exceptions list, use the tree control to select the individual exception or category of exceptions whose handling you want to change.
- Under When the exception is thrown:
- Choose Break into the debugger if you want execution to break as soon as the exception occurs, without giving the handler a chance to execute. If you choose this setting, the icon next to the exception or category name appears as a large red ball with an "X" through it.
- Choose Continue to give the handler a chance to fix the problem. If you choose this setting, the icon next to the exception or category name appears as a large red ball with an "X" through it. If you choose this setting, the icon next to the exception or category name appears as a large gray ball.
- Choose Use parent setting to accept the default setting currently specified for the category which the exception is part of. (This option is not available if you chose a category, rather than an individual exception, in step 2.) If you choose this setting, the icon next to the exception or category name appears as a small gray ball.
The icon next to an exception name (or category name) changes to reflect the setting for When the exception is t
- Under If the exception is not handled:
- Choose Break into the debugger if you want execution to break after the handler executes if the handler is not successful in fixing the problem.
- Choose Continue if you want execution to continue after the handler executes, regardless of whether the handler is successful or not.
- Choose Use parent setting to accept the default setting currently specified for the category which the exception is part of. (This option is not available if you chose a category, rather than an individual exception, in step 2.)
- Choose the option.
- Click OK.
When the debugger breaks on an exception, 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. If you continue execution of the after an exception, a dialog box asks if you want to pass the exception back to the handler. At that point you have three options:
- You can click No. This is the option you usually want to pick if you successfully fixed the problem.
- You can click Yes, and the exception handler will be invoked. If the exception handler cannot fix the problem, the debugger halts the program and notifies you.
- You can click Cancel, in which case debugging and program execution end.
By default, the Exceptions dialog box lists the most common exceptions in each category. You can add other exceptions to a category. These exceptions are stored with the project and will be available the next time you open and run the project.
You can delete user-added exceptions from the list. There's also a procedure for deleting all user-added exceptions. You cannot delete the default exceptions, however.
See Also
Exceptions Dialog Box | Using the Debugger