Exception Handling (Debugging)
This topic applies to:
Pro, Premium, and Ultimate
An exception is an abnormal situation that happens while a program is running. Exceptions are frequently indications of problems that you have 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 dialog box.
The debugger might or might 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"). For more information, 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. Make sure that you 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:
Common language runtime exceptions
Managed debugging assistants
Native run-time checks
Most exceptions have handlers that are designed to respond to an exception when it occurs. This gives the program an opportunity 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, and C#, the debugger now features a new Exception Assistant that provides more information when an exception occurs.
The following topics provide information on handling exceptions:
(Visual Basic and Visual C# only) If an uncaught exception occurs with the Exception Assistant turned off, a pseudovariable $exception is added to the Locals window. You can expand this pseudovariable to see information on the exception.