2006/03/23

Exception Handling

The following are some of the generally accepted principles of exception handling:

1. If you can’t handle an exception, don’t catch it.
2. If you catch an exception, don’t swallow it.
3. Catch an exception as close as possible to its source.
4. Log an exception where you catch it, unless you plan to rethrow it.
5. Structure your methods according to how fine-grained your exception handling must be.
6. Use as many typed exceptions as you need, particularly for application exceptions.


"Best Practices in EJB Exception Handling"
http://www-106.ibm.com/developerworks/java/library/j-ejbexcept.html

"Best Practices for Exception Handling"
http://www.onjava.com/pub/a/onjava/2003/11/19/exceptions.html

"Designing with Exceptions"
http://www.javaworld.com/jw-07-1998/jw-07-techniques.html

"Exceptions in Java"
http://www.javaworld.com/jw-07-1998/jw-07-exceptions.html

"Exceptional Practices, Part 1"
http://www.javaworld.com/javaworld/jw-08-2001/jw-0803-exceptions.html

"Exceptional Practices, Part 2"
http://www.javaworld.com/javaworld/jw-09-2001/jw-0914-exceptions.html

"When catching exceptions, don't cast your net too wide"
http://www.javaworld.com/javaworld/javatips/jw-javatip134.html

"Use nested exceptions"
http://www.javaworld.com/javaworld/javatips/jw-javatip91.html

"Beware the dangers of generic exceptions"
http://www.javaworld.com/javaworld/jw-10-2003/jw-1003-generics.html

No comments: