Reputation: 78545
In the VS debugger, un-caught exceptions result in the program breaking at the point the exception is throw (or near enough) and in a state that lets you look at all the stack frames and there local variables up to that point.
Is there a way to get this same result (break at throw) but for an exception is caught at a particular point? I'm not interested in doing this for ALL exceptions or even all exception of a given type (that could get useless real quick) but if I could do it for a single try or catch block I'd be happy
somewhat related:
Upvotes: 3
Views: 2063
Reputation: 46579
Yes, you should be able to put a breakpoint on the last brace of your catch block. Or the throw command if you're re-throwing.
If you just need to have a breakpoint on any exception inside of a certain method do a re-throw.
try { }
catch (Exception exc)
{
throw; // <-- breakpoint here
}
Edit: I was once in the habit of putting breakpoints on just about all of my exceptions. Found out the hard way that this slowed down the debugger in a big way once I got to about 25 breakpoints. May only be relevant to VS2005.
Edit2: The location that caused the exception ought to be in the exc object's StackTrace.
Upvotes: 3
Reputation: 30418
Does the Debug -> Exceptions dialog do what you want? You can select which Exceptions that will cause VS to break, regardless of whether they are caught or not. I don't know of a way to do this for only a certain part of the code, only based on the type of the exception thrown.
Upvotes: 6