Is There a Global Error Catch function?

NeuralJack

Centurion
Joined
Jul 28, 2005
Messages
138
I was thinking about how nice it would be to have a global try/catch that would catch errors not handled by the subroutines themselves.

this would be sort of a last-resort safety net to stop your program from just crashing on the user if something odd happens.

Currently most of my functions have a try/catch statement, but if there was a global version it would save lots of code
 
Try/Catch are generally used in places where an error is reasonably likely, for example when communicating with something outside your own application (File IO, Network comms etc). Due to the way they are used you will generally have a good idea what the error will be and what your application should do about it. For example if a subroutine fails to open a file, you might tell the user then continue regardless. How would you apply such a system to a global Try/Catch? If the statement will catch everything you've failed to account for it's an unknown error, and theres not really alot of point in catching an unknown error. Say you did catch it, what would you then do with that error, the chances are if it's not an error you anticipated, your application won't function for long afterwards.
 
Ya, I know. The main reason for wanting such a general thing is to essentially give the user the ability to Close the program or Continue (knowing a major unknown error has occured).
Also what you can do is catch the error type and other information (sub routine name, line number, etc) and have a form where that error information can be sent via email, or something to the programmer.

I realize any responsible programmer is going to try hard to cover all bases for catching errors.. but was just wondering if there could be a super safety net.

Cags said:
Try/Catch are generally used in places where an error is reasonably likely, for example when communicating with something outside your own application (File IO, Network comms etc). Due to the way they are used you will generally have a good idea what the error will be and what your application should do about it. For example if a subroutine fails to open a file, you might tell the user then continue regardless. How would you apply such a system to a global Try/Catch? If the statement will catch everything you've failed to account for it's an unknown error, and theres not really alot of point in catching an unknown error. Say you did catch it, what would you then do with that error, the chances are if it's not an error you anticipated, your application won't function for long afterwards.
 
Not sure if this helps...but we have an error class that we direct all of our error calls to as well as all close/end events (i.e. instead of system.environment.exit(0), we use LocalErrorLink.GoodExit(0)).

By funneling everything through this class, you are guaranteed to have one exit point where all errors/exit calls are sent...which could give you the "global" spot to decide what to do if an error occurs.
 
Back
Top