Managing Exceptions in Visual Studio

You can configure Visual Studio 2008 for exception handling in the Exception Assistant and Exceptions dialog boxes. The Exception Assistant dialog box provides helpful information to developers when an unhandled exception is raised. The Exceptions dialog box manages how the Visual Studio debugger handles exceptions.

The Exception Assistant

The Exception Assistant appears in Visual Studio when an unhandled exception occurs. It displays a translucent frame that partially obfuscates the application code. The source code that prompted the exception is highlighted and tethered to the Exception Assistant dialog box, which is shown in Figure 12-3.

The Exception Assistant dialog box for a divide-by-zero exception

Figure 12-3. The Exception Assistant dialog box for a divide-by-zero exception

The Exception Assistant header identifies the unhandled exception and offers a brief explanation. The Troubleshooting Tips pane offers hints to diagnose the exception. Each hint is also a link to further information. The Actions pane specifies two actions:

  • View Detail displays the properties of the exception object.

  • Copy Exception Detail To The Clipboard copies basic information on the exception to the Clipboard.

The Exception Assistant can be disabled or otherwise configured by selecting Options from the Tools menu. Configure the Exception Assistant in the Debugging category of the Options dialog box.

The Exceptions Dialog Box

In the Exceptions dialog box, the Visual Studio debugger can be instructed to interrupt on first-chance exceptions. Open the Exceptions dialog box by selecting Exceptions from the Debug menu. Figure 12-4 shows the Exceptions dialog box.

The Exceptions dialog box

Figure 12-4. The Exceptions dialog box

The Thrown and User-unhandled columns contain a series of check boxes, which are organized via the Name column into categories and specific exceptions. Exceptions with the Thrown check box selected are interrupted as first-chance exceptions. For code in a try block, the debugger breaks at the origin of the exception, which is often useful. While developing an application, it can be instructive to be notified of an exception that otherwise would be consumed in an exception handler. The second column selects specific exceptions to interrupt in case of a second-chance exception. The Add button in the Exceptions dialog box adds application exceptions to the list of available exceptions. Of course, added exceptions can be deleted later.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.216.59