Reputation: 353
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.
Upvotes: 12
Views: 2141
Reputation: 1313
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!
Upvotes: 4
Reputation: 75982
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.
Upvotes: 3
Reputation: 81884
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.
Upvotes: 7
Reputation: 421978
Yes, go to "Debug" menu, select "Exceptions...", check "Thrown" for "Common Language Runtime Exceptions"
Upvotes: 22