Thursday, June 9, 2011

Visual Studio Break When Exception Thrown

Maybe some of you know this, maybe some of you don’t. But I just learned about it. Apparently I’m a old man programmer because I normally just look at the code and try to solve it without debugging the application, or I write it out somewhere.

I’ve been trying to track down this wiggly bug in my factory pattern code, but it was a slippery bugger. I finally asked somebody for some help and they suggested that instead of all my try/catch’s I use the Break when Exception is thrown. By default Visual Studio only breaks when the exception is unhandled in the user code. For me this was some distance from where the exception was thrown.

So if you want to throw the error in the code where the error occurs and not wait for it to catch. You can select the Debug menu, then Exceptions (or use Ctrl-Alt-E) which will bring up this dialog box:

image

Check the box under Thrown for the “Common Language Runtime Exceptions and viola. You are set.

No comments:

Post a Comment