Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

handling all runtime errors everywhere. how to do?

Status
Not open for further replies.

thesleepylizard

Programmer
Mar 18, 2002
41
AU
Hi,

I have a large VB6 program. I want to handle every error in every subroutine and event. So, whenever it crashes, it can call a public sub Handle_Any_Error which will calmly tell the user what's happened.

I've tried several methods. The obvious one is to edit every subroutine in the project so it contains:

Code:
Private Sub MySub
    on error goto MySub_Err

    '
    '
    'code that might crash
    '
    '

    exit sub
Mysub_Err:
    Handle_Any_Error ()
    resume next
End Sub


This is the normal way of doing it. BUT. To write this into hundreds of subroutines really is not the best way to do it.


I have tried speedening up this process by using some rather cheeky code:

Code:
Private Sub MySub
    On Error Goto Error_Handler
    If False then
Error_Handler: Handle_Any_Error ()
    end if

    '
    '
    'code that might crash
    '
    '

End Sub


This is very cheeky. I can just grab the first 4 lines in the subroutine and copy them into the start of every other subroutine!


However, I really really wish there was some way to say "Whenever an error occurs, just call this sub rather than call the default error message", or at least some option somewhere.


I'm sure I'm not the only person who's wanted to globally handle all errors in a program! Does anyone else have any ideas about the most efficient (coding-wise) method of handling all errors?

Thanks for your time,
-Sleepy
 
lizard,

Here is a thread from the other day that talks about it.
thread222-241592

CraigSander's last post to the thread gives a way to cut down on your error handling. Hope this helps. Anything is possible, the problem is I only have one lifetime.
[cheers]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top