JohnDoeSr
asked on
Beginner Error Handler Question
As my beginners VB book instructs, I use 'On Error Goto ErrorCatcher12' statements to catch errors. I then follow up just above the 'end sub' line with the corresponding error handler label like"
exit sub
ErrorCatcher12:
If Err.Number = 91 Then
sleep 4
Goto Label4
Else
Resume
End If
The problem with this is that if there is an error triggered that is other then err.number 91, i'm screwed! I've gone so far as to replace Resume with Msgbox(err.num & " " & err.description) just to see what kind of other error is triggered but then when running the program (during design) I don't get that convenient error box that asks if I'd like to DEBUG or END.
I hope I've explained it clearly enough. Thanks!
exit sub
ErrorCatcher12:
If Err.Number = 91 Then
sleep 4
Goto Label4
Else
Resume
End If
The problem with this is that if there is an error triggered that is other then err.number 91, i'm screwed! I've gone so far as to replace Resume with Msgbox(err.num & " " & err.description) just to see what kind of other error is triggered but then when running the program (during design) I don't get that convenient error box that asks if I'd like to DEBUG or END.
I hope I've explained it clearly enough. Thanks!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
also:
instead of "resume", use "resume next"
that will skip the errorneous code (eg divide by 0)
and execute the next line
ASKER
Thanks a bunch. Both of those answers helped a ton.
When I'm debugging my code, I add line numbers to aid in tracking down the error. MZTools ( http://www.mztools.com/ ) has some great tools for this purpose and free!
Then once the line numbers have been added, you simple need to do something like this to retreive the error details
MsgBox "An Error occurred at line number : " & Erl & vbLf & vbLf & err.Number & " - " & err.Description
This will give the exact line the error occured on, using Erl.
Regards,
Wayne