Export (0) Print
Expand All
5 out of 17 rated this helpful - Rate this topic

How to: Break When an Exception is Thrown

The debugger can break execution of your application immediately when an exception occurs, giving you a chance to debug the exception before a handler is invoked.

If you are debugging with How to: Step Into Just My Code enabled, the behavior is slightly different. With Just My Code enabled, the debugger ignores first-chance common language runtime (CLR) exceptions that are thrown outside of My Code and do not pass through My Code. If the exception is completely unhandled, however, the debugger always breaks.

NoteNote

When you set the debugger to break when a CLR exception is thrown and the debugger breaks on a CLR exception, the line highlighted by the debugger may be slightly off in some cases. This can occur, for example, if you throw an exception from managed code within an if statement. The debugger highlights the line with the next CLR instruction to be executed, which is the line after the throw rather than the line with the throw.

While Using the Exceptions Dialog Box

By default, the Exceptions dialog box lists the most common exceptions in each category. You can add your own exceptions and delete exceptions you have added. Visual Studio saves the list of added exceptions with the solution data, so the exceptions will be available the next time you open and run the project.

NoteNote

The Exceptions dialog box provides keys for setting controls without using the mouse. The hot keys are indicated by underlining in the control labels. If you have Windows themes disabled, the underlining will not be visible, although hot keys will still work. To view the hot-key underlining, enable Windows themes using the Windows Control Panel.

For more information, see How to: Add New Exceptions and How to: Delete User-Added Exceptions.

To break execution when an exception is thrown

  1. On the Debug menu, click Exceptions.

  2. In the Exceptions dialog box, select Thrown for an entire category of exceptions, for example, Common Language Runtime Exceptions.

    -or-

    Expand the node for a category of exceptions, for example, Common Language Runtime Exceptions, and select Thrown for a specific exception within that category.

See Also

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.