Share via


Breaking into the Debugger

It is not always convenient to run a program from within a debugger. Programs often run on test computers and, only when an error occurs, is it necessary to attach a debugger to examine the cause of the failure in greater detail.

If you remove the comment characters from the call to Throw in the Main method of Calc.cs|Calc.vb and recompile, the following line executes when you attempt to close the application.

throw(new System.Exception()); //C#

or

Throw New System.Exception()  'VB

A run-time exception brings up the Common Language Runtime Debugging Services dialog box:

which gives to the option of exiting the application, debugging in the Runtime Debugger (CorDbg.exe), or debugging in the Visual Studio .NET debugger if that product is installed.

Debugging is handled somewhat differently if the unhandled exception occurs in code called by Windows Forms. In these situations, Windows Forms displays a different dialog, which gives the user only the option of trying to continue the application. However, when this dialog is displayed, it is also possible for a developer to attach to the process using any available debugger.

See Also

Trace and Debug Classes | Debugging and Optimization | The Microsoft CLR Debugger | Debugging ASP.NET Web Applications | Appendix A: For Additional Information | Appendix B: Runtime Debugger (CorDbg.exe)