Share via


Exception Handling (Debugging) 

An exception is an abnormal situation that happens while a program is running. Exceptions are often indications of problems that you need to debug. When an exception occurs, the debugger writes an exception message to the Output window, unless it is disabled in the General, Debugging, Options Dialog Box.

The debugger may or may not break execution when exception occurs.

  • If a non-ASP.NET exception occurs and is not handled, the debugger always breaks execution.

  • You can tell the debugger to break execution immediately when an exception is thrown, before any handler is invoked. For more information, see How to: Break When an Exception is Thrown.

  • If you are debugging with How to: Step Into Just My Code, you have a third option. You can tell the debugger to break on any exception that is not handled by a handler in user code ("My Code"). See How to: Break on User-Unhandled Exceptions.

  • ASP.NET has a top-level exception handler that handles exceptions to show error pages to browser users. That top-level exception handler will stop an unhandled exception from breaking into the debugger unless Just My Code is turned on. Be sure to enable Just My Code for ASP.NET debugging.

    Remember, if an exception occurs and is not handled at all, the debugger always breaks. The user-unhandled setting does not change that.

The Visual Studio debugger recognizes the following categories of exceptions:

  • C++ exceptions

  • Common language runtime exceptions

  • Managed debugging assistants

  • Native run-time checks

  • Win32 exceptions

Most exceptions have handlers that are designed to respond to an exception when it occurs, giving the program a chance to recover from the abnormal situation. Native run-time checks do not have handlers.

In a Visual Basic application, the debugger represents all errors as exceptions, even if you use On Error–style error handlers.

For Visual Basic, C#, and J#, the debugger now features a new Exception Assistant that provides more information when an exception occurs.

The following topics provide information on handling exceptions:

See Also

Tasks

How to: Step Into Just My Code

Concepts

Debugger Security

Other Resources

Exception Assistant
Debugger Roadmap