News for hackers. Stuff that matters.
Re:What do you do when you've caught an exception? by damienkatz on Monday March 02, 2009 @11:43AM (#500260)
Set it free. If it crashes the program, it was yours all along.
Re:What do you do when you've caught an exception? by acangiano on Monday March 02, 2009 @11:49AM (#500274)
Damien jokes about this, but he wrote a great article about error handling: http://damienkatz.net/2006/04/error_code_vs_e.html
Re:What do you do when you've caught an exception? by paul_houle on Monday March 02, 2009 @12:14PM (#500312)
I like that article!
Re:What do you do when you've caught an exception? by russell on Monday March 02, 2009 @03:12PM (#500547)
Paul makes some very good points. He advocates exception handling at the level of the unit of work. The problem is what is the unit of work? As an example, I was setting up a new Jboss installation and deployment of an application that I am only getting familiar with. Catalina threw an exception about something in the configuration, but didn't log anything. Finally, JBoss caught the exception and just logged that the deployment had failed. The piece of code that found the problem could have told me what was wrong.

Paul says that checked exception are a horrible mistake, because they cause premature catching of exceptions, because ignoring the exception means that the programmer has to change the signature of his method. I find swallowed exceptions all over the place in reading code. And methods in the Sun libraries exacerbate the problem by throwing multiple checked exceptions that have to be swallowed. So to keep method signatures at a reasonable length, more swallowed exceptions. Generic exceptions with error codes, like SQLException, would make more sense.

Given the reality of Java Exception handling, I favor catching the exception at the point where a reasonable error message can be composed and logged., Then throwing an unchecked exception to be caught at the level of the unit of work.

Finally, Paul says always use finally to clean up your mess.

Re:What do you do when you've caught an exception? by lbolognini on Monday March 02, 2009 @11:46AM (#500271)
Is it any good fried?