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!
JohnDoeSrAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wayne Taylor (webtubbs)Commented:
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
0
PSSUserCommented:
In the VB IDE go to the options menu. There is a tab in there where you can tell VB to either "Break on all errors" or "Break on unhandled errors". You may find the first more useful while trying to track down errors, the second when trying to test your error handling code.
0
dancebertCommented:
If Err.Number = 91 Then
    sleep 4
    Goto Label4


' put as many (or few) of the ElseIfs as you need to handle known errors
Elseif err.number = <some other number you want to handle> then
    <handle the error>


' these are the errors that can't be handled, so let the app die
else
    err.raise err.number & ", " & err.description
End If
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mark_FreeSoftwareCommented:

also:

instead of "resume", use "resume next"

that will skip the errorneous code (eg divide by 0)
and execute the next line
0
JohnDoeSrAuthor Commented:
Thanks a bunch. Both of those answers helped a ton.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.