Ian Bicking: the old part of his blog

Re: Good catch all exceptions

> BTW, I've been wanting a really good generic library to handle unexpected exceptions

I've had really good luck with Mongoose (http://themongoose.sourceforge.net/).  You register exception handlers for uncaught 
exceptions.  It comes with one that does logging, one that emails, etc.  One other interesting feature is that it hashes the 
exception type, file name, function name, and other stuff to generate a "Mongoose Incident Identifier(TM)" so you 
(theoretically) have a unique identifier for each independent bug.
Comment on Good catch all exceptions
by Ian Bicking


Cool -- I hadn't seen Mongoose before, I'll definitely check it out.
# Ian Bicking

Catching all exceptions is bad, because it shows that you do not know how your program works. 
Any exception IS predictable, we are talking computer programs, not random static.

Sometimes you need a program to crash or properly raise exceptions. Reraising only works if 
the clean-up action doesn't raise any exceptions, as discussed earlier.  Here's the deal, 
only catch exceptions that you except. If an exception you don't expect is raised that 
means you have a bug, you fix the bug and add the proper handling of that exception.

I've seen many Java programmers do

try {
} catch (Exception e) {
  System.err.println("Error occurred: " + e.getMessage());

and this sucks TREMENDOUSLY if you are trying to debug a program. Sometimes you want your 
program to crash and burn, just to let you know that something is really wrong.
Even user input is predictable enough to write exact error handling.
Catching all exception may cure the symptoms, but not the cause; fix the cause instead.

Finally, it might be OK to catch all exceptions if it is imperitive that your 
process/thread do not stop. In that case, try catching the exception at the highest 
possible level and log with full stacktrace and give as much debug input as possible.
However, on many systems bugs might just as well end the process and send the stacktrace 
to stderr. I've seen too many bad things happen with processes that should have been 
terminated due to bugs, but poor programming let the processes continue doing bad things 
to the rest of the system.
# Ian Bicking

I was surprised to be ego-Googling for my Mongoose project a short time after there was some discussion about it! :-)

I'm intrigued to know who wrote "I've had really good luck with Mongoose" and what they've been using it for, as I wasn't aware of anyone who was actively using outside its original deployment. (I was confused because that comment appeared to be Ian replying to himself.)

I liked the Incident Identifier idea a lot and would be most interested in it being adopted by other similar projects.

# Phil

Sorry, I edited the comment (for formatting) and that messed up the attribution... maybe I have it back now. It was Denis Dube: http://msdl.cs.mcgill.ca/people/denis/

# Ian Bicking