EJB exception handling is an important but rarely written-about topic. However, a new article on developerworks discusses exception handling in EJB and best practices for dealing with them.
Read Best Practices in EJB Exception Handling
Description of various types of Exception is very concrete. However, the article does not give any clear picture of design patterns. It would have been more useful if author spends some more time on design patterns.
He made good points about when to warp an exception and throw it as a system or an application exception. Also writing your custom RuntimeException class for the purpose of logging exceptions is cool.
A good discussion, although I disagree with the premise that you should log your exceptions where you catch them.
What about when you're writing adapters, or utility classes etc. These are typically used across many different areas of your code base, so the utility or adapter can't be the place to put the logging code.
Logging is supposed to be contextual, and the best logging practices I have seen focus on logging things in the context of what the application is meant to do, not how it is going about it. That type of logging is typically done at a relatively high level in the system, which is where I would expect exceptions to get logged, not down in the depths of where they first occur.
Just my 2c worth. Good article though. Personally I am fed up with trying to trouble-shoot other peoples code when exceptions get swallowed or mess up STDERR.
Now, if someone could just tell the JCE folks to do some exception chaining perhaps we could all figure out what the hell is actually happening when we get "Error getting Trusted Certs" exception from JCE in WebLogic! :)
I would like to know what is the best strategy of throwing exception from EJBs in the case of RMI/IIOP. Any suggestion is greatly appreciated.
Its a good article. Can anyone give details on how to handle application exceptions when the ejb exposed as webservices throws an exception, how to catch that in the webtier which is a struts based and display appropriate message to the end user.