I rememeber seeing a thread a long time ago about how people trap errors and
resume, but I can't find it now. I'm pretty sure either Ken Halter or Larry
Serflaten demonstrated something that was pretty cool for trapping errors when
in the IDE and still being able to find out the exact line that had the error
and halting execution, but when compiled it wouldn't stop the user.
My issue is that I normally have VB set to stop on all errors because my coding
style is such that any error I find must be dealt with when programming if at
all possible, and I'll goto great lengths to avoid using any kind of "On Error
Resume Next" for handling things like finding out if an array is dimensioned.
Well, some requirement has blown that out of the water, and now my IDE is
breaking all over the place because of some collection code that I HAVE to use.
I remember that code that I'm looking for had some sort of Resume statement in
the error handler, so that the person could check the error that occurred, then
"Resume" to find what line it actually happened on.
Larry or Ken (or anyone else out there) is this ringing any bells?
Matt
Tim Baur - 30 Jul 2004 16:26 GMT
> I rememeber seeing a thread a long time ago about how people trap
> errors and resume, but I can't find it now. I'm pretty sure either
[quoted text clipped - 21 lines]
>
> Matt
Step through this.
Public Sub TryMe()
On Error GoTo MyError
MsgBox 4 / 0
Exit Sub
MyError:
MsgBox Err.Description
Resume
End Sub
Ken Halter - 30 Jul 2004 16:30 GMT
> I rememeber seeing a thread a long time ago about how people trap errors and
> resume, but I can't find it now. I'm pretty sure either Ken Halter or Larry
> Serflaten demonstrated something that was pretty cool for trapping errors when
> in the IDE and still being able to find out the exact line that had the error
> and halting execution, but when compiled it wouldn't stop the user.
Well... my "trick" (probably learned it here) works only inside the IDE
but it's great for finding the line that raised the error.
'=============
Private Sub Form_Load()
Const ErrorLocation = "Form1:Form_Load"
On Error GoTo ErrorTrap
'==============================================================
Dim a As Integer
Dim b As Integer
Dim c As Integer
b = 12
c = b / a 'div by zero error
'==============================================================
Terminate:
'clean up code here
Exit Sub
ErrorTrap:
MsgBox "Error " & Err.Number & vbCrLf & Err.Description _
, vbCritical, ErrorLocation
Debug.Assert False 'Stops here in the IDE
'Compiled code will run this and get out of the procedure
Resume Terminate
'When VB stops on the Debug.Assert statement,
'Select the 'Resume' line below, hit Ctrl-F9 then F8
'VB'll jump directly to the line that raised the error
'This line will never run in compiled code (no way to get here)
Resume
End Sub
'=============
Note that you can add the Resume line at runtime if the file's not set
to 'Read-Only'. I have an add-in (CodeSmart) that adds all of the error
handling stuff with a single Ctrl-Keystroke (including the ErrorLocation
constant)

Signature
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Please keep all discussions in the groups..
YYZ - 30 Jul 2004 16:38 GMT
> > I rememeber seeing a thread a long time ago about how people trap errors and
> > resume, but I can't find it now. I'm pretty sure either Ken Halter or Larry
[quoted text clipped - 4 lines]
> Well... my "trick" (probably learned it here) works only inside the IDE
> but it's great for finding the line that raised the error.
Exactly what I was looking for. Thanks so much (and you too, Tim -- yours is
simpler but illustrates what I was trying to figure out).
I just learned about Debug.Assert a few weeks ago, and keep being shown uses for
it that I never thought of.
Matt
Tim Baur - 30 Jul 2004 16:45 GMT
Yeah sure. One thing I'm doing write now is putting
On Error GoTo 0 'MyError
All over the place while I develop. When I compile, I'll simply do a
global search and replace for "GoTo 0 'MyError" --> "GoTo MyError"
Bob Butler - 30 Jul 2004 17:15 GMT
> Yeah sure. One thing I'm doing write now is putting
>
> On Error GoTo 0 'MyError
>
> All over the place while I develop. When I compile, I'll simply do a
> global search and replace for "GoTo 0 'MyError" --> "GoTo MyError"
If you right-click on the code in the IDE and choose "toggle" to can set it
to "break on all errors" which I think will get you the same effect without
having to remember to do the global replace before compiling.

Signature
Reply to the group so all can participate
VB.Net... just say "No"
Tim Baur - 30 Jul 2004 17:23 GMT
>> Yeah sure. One thing I'm doing write now is putting
>>
[quoted text clipped - 7 lines]
> effect without having to remember to do the global replace before
> compiling.
DO'H!
Thanks Bob. I never realized that was there. I owe you a beer.
-Tim