Managing Exceptions in Visual Studio

Managing Exceptions in Visual Studio

Visual Studio 2005 can configure exceptions for debugging. The Exception Assistant provides helpful information to developers when an unhandled exception is raised. The Exceptions dialog box alters how the Visual Studio debugger handles exceptions.

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 window. The Exception Assistant is shown in Figure 9-3.

Image from book
Figure 9-3: The Exception Assistant

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

  • New Detail displays the properties of the exception object.

  • Copy Exceptional Detail To The Clipboard copies basic information on the exception onto the Clipboard.

The Exception Assistant can be disabled or otherwise configured from the Tools menu. Select the Options menu item. Configure the Exception Assistant in the Debugging pane.

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 from the Debug menu. Choose the Exceptions menu item. Figure 9-4 shows the Exceptions dialog box.

Image from book
Figure 9-4: The Exceptions dialog box

The Thrown and User-unhandled columns have a series of option boxes that are organized into categories and specific exceptions. Visual Studio debugger interrupts on first chance exceptions for exceptions selected in the Thrown column. For protected code, the debugger intercedes before the exception is caught. In the development phase of an application, it can be instructive to be notified of exceptions that would otherwise be consumed in an exception handler. The second column selects specific user-handled exceptions to break on. The Add button appends application exceptions to the list of available exceptions that are selectable in the dialog box. These exceptions can later be deleted.