Last line for Exception

  • Thread starter Thread starter Troy Stauffer
  • Start date Start date
T

Troy Stauffer

Is there any way to do the same as Resume when you are in
the debugger in an exception handler? I want to go back
to the exact line that caused the exception. How do i do
this? Currently i disable the exception handler and add
the on error goto and then perform a resume but that seems
really dumb
 
I realize this but that is not what i am asking here. I
am asking for a way to perform the equivalent of the old
Resume. If i have an exception occur and i place a
breakpoint in the catch statement, i would like a way to
say "show me the line that caused the exception" much the
same way Resume worked when using On Error Goto
 
If you just want to know which line threw the exception, look at the stack
debug window. It took me a bit to get used to coming from VB6.

I would suggest that needing to resume a line after an exception is thrown
could probably be redesigned, possibly by using finally. My problem in VB6
with this was if a programmer depended on it and I was looking at their
code, I didn't know what their intent was.

The other way to redesign is to use a nested exception, so that you try just
the line you expect to throw it. I think this is really close to resume
behavior. Something like this:

Try

Try
'The line I expect to throw
Catch ex2 as Exception

End Try

Catch ex as Exception

End Try
 
Sorry, maybe i am not making myself clear. If you look at
the stack debug window, it simply tells you what line the
exception is on NOT which line threw it. If the routine
which i am debugging has 30-40 lines wrapped in a try
catch and i can't change that, then it would be nice to
know where that exception happened. The resume feature in
the On Error was perfect. Let me also say this is not
something i desire at runtime, only debugging time.
Although there are also cases where i performed a resume
even a runtime once i fixed the error. there were times
in VB6 when you have no choice but to error out first and
then fix the error. I would like that same type of
functionality
 
i figured it out. You can't do what i am asking but if
you print the exception out using ToString, it will tell
you the exact line it happened on
 
ahh, to get the line all you need to do is ToString the exception that
is thrown. Many people just look at Message and don't realize that
ToString will get you everything about where it came from.


}
catch( Exception ex )
{
Debug.WriteLine( ex.ToString() );
}

is that what you were looking for?


Allen Anderson
http://www.glacialcomponents.com
 
ahh, to get the line all you need to do is ToString the exception that
is thrown. Many people just look at Message and don't realize that
ToString will get you everything about where it came from.

This information is also available from the 'StackTrace' member.

-mbray
 
while this does serve the immediate need, it would still be nice to have
the Debugger.PutMeOnTheLineThatCausedTheCrash method
 
Back
Top