views:

649

answers:

4

One of the things I loved about VB6 is that you had the ability to tell the development environment to break on all errors regardless of what error handling you had set up. Is it possible to do the same thing in VS2008 so that the debugger will stop on any error even if it happens inside a try-catch statement?

The problem is particularly hard when you are processing a file with say 500 records and it is failing on one of them - who knows which one - You don't want to modify the code so that your for counter is initialized outside that for loop - that is sloppy long-term. You just want the debugger to know to stop because of some setting you put somewhere.

+15  A: 

Yes, go to "Debug" menu, select "Exceptions...", check "Thrown" for "Common Language Runtime Exceptions"

Mehrdad Afshari
You beat me for seconds =)
Juan Manuel
+5  A: 

Sure, press Ctrl-Alt-E to bring up the exceptions window and tick the Thrown checkbox on Common Language Runtime Exceptions

That will stop the execution, open the source code where the exception was thrown, and tell you with a message window what error it is, pointing at the line it was thrown.

Juan Manuel
+3  A: 

In Visual Studio, you can go to Debug -> Exceptions... and check the check box to any particular exception or a class of exceptions you want VS to break at when generated.

There are five categories of exceptions - C++, Common Language Runtime, Managed Debugging Assistants, Native Run-Time Checks and Win32. For the most part you are interested in the CLR ones, though if you are doing COM interop, you might want some of the others as well.

Franci Penov
+4  A: 

I discovered that checkbox everyone is talking about during debugging of a project at work once. I flipped it on and all of a sudden I'm getting all these exceptions thrown all over the place! Turned out the dev's on another team had been using Try-Catch as a mask for easily preventable conditions (but were too lazy to trap themselves). BAD!

Mike at KBS
+1 because it's funny but it's not. I've encountered this myself. Not fun.
Kibbee