Link to home
Start Free TrialLog in
Avatar of JohnDoeSr
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!
Avatar of Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs)
Flag of Australia image

Hello JohnDoeSr,

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
SOLUTION
Avatar of PSSUser
PSSUser
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

also:

instead of "resume", use "resume next"

that will skip the errorneous code (eg divide by 0)
and execute the next line
Avatar of JohnDoeSr
JohnDoeSr

ASKER

Thanks a bunch. Both of those answers helped a ton.