I'm writing EJB3 application and wonder about exception handling policy. I'll have both some checked application exceptions and some runtime application exceptions. I know I can catch them in my client, but what if another regular runtime exception will be thrown? It'll be wrapped in E开发者_开发技巧JBException, right? If so, should I catch this exception? Or let's say I'd like only a subset of runtime exceptions to be handled in a different way (e.g. to be able to show more detailed message than "Business service call failed"). What is your exception structure and handling policy for regular EJB application and for e.g. Struts 2 client.
If you don't catch such Exceptions then what's going to happen? Some ugly Servlet Exception gets sent back to a browser or some other such unfriendly outcome I suppose.
So yes catch, display reassuring message. If by default the framework you are using already does that, then well and good, otherwise you'll just need to code it yourself.
I'm sceptical that it's often useful to differentiate from UI/servlet perspective the exact cause of the problem, be it NullPointer, ArrayIndex, OutOfMemory or whatever. It's just that the "service" as represented by the EJB failed, probably because of a coding or infrastructure error. Not a lot the user can do about that, so no special hierarchy for me.
精彩评论