How to Handle Exceptions in EJB

August 28, 2003 on 8:29 pm | In Java |

From the article on DeveloperWorks.

Principles of 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.

Point 1 is obviously in conflict with Point 3. The practical solution is a trade-off between how close to the source you catch an exception and how far you let it fall before you’ve completely lost the intent or content of the original exception.

Note: These principles are not particular to EJB exception handling, although they are applied throughout the EJB exception-handling mechanisms.

Technorati Tags: ,

Related Posts:

1 Comment »

RSS feed for comments on this post.

  1. […] In the past, I have written about exception handling best practice and EJB exception handling. […]

    Pingback by Java and friends » Robust Java Exception Handling — 20 July 2006 #

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>





Powered by blog.mu with Pool theme design by Borja Fernandez.