10/30/2006

Visual Studio 2005 Debugging Tip

Have you ever been debugging an ASP.NET 2.0 application and you see "First Chance Exception XXX" in the Output Window while you are putting the app through its paces in Debug mode, but the IDE never breaks on any of them?

And you are saying to yourself, How can I debug this thing if all I see is cryptic messages in the Output Window but no source code, line numbers or anything else?

What you want to do is tell the Debugger to Break on all Managed Code Exceptions. Here's how:

1) In the IDE, up top, hit "Debug" and Choose "Exceptions". You will see a dialog with a Treeview (collapsed) the second node of which reads "Common Language Runtime Exceptions". At the right will be a checkbox. Check this checkbox. (If you want, you can expand the treenode and pick and choose which kinds of exceptions you want the debugger to break on when thrown). You need to check this (these) because the default behavior is "continue".

In fact, you can even add custom exceptions that aren't in the list, that you want the debugger to break on. CTRL-ALT-E brings this dialog up.

Exceptions Dialog- Click to Enlarge

2)Now when you get an exception, everything will come to a screeching halt and you'll break into the debugger. Ain't technology grand?