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 EJBException, 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.
我正在编写EJB3应用程序,并对异常处理策略感到疑惑。我将有一些已检查的应用程序异常和一些运行时应用程序异常。我知道我可以在我的客户端中捕获它们,但是如果抛出另一个常规运行时异常怎么办?它将被包装在EJBException中,对吧?如果是这样,我应该抓住这个例外吗?或者假设我只想以不同的方式处理运行时异常的子集(例如,能够显示比“业务服务调用失败”更详细的消息)。什么是常规EJB应用程序的异常结构和处理策略,例如Struts 2客户端。
1 个解决方案
#1
0
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.
如果你没有抓住这样的例外,那会发生什么?一些丑陋的Servlet Exception被发送回浏览器或其他一些我认为不友好的结果。
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.
我怀疑从UI / servlet角度区分问题的确切原因通常是有用的,无论是NullPointer,ArrayIndex,OutOfMemory还是其他什么。只是由EJB表示的“服务”失败,可能是因为编码或基础结构错误。用户不能做很多事情,因此对我来说没有特殊的等级。
#1
0
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.
如果你没有抓住这样的例外,那会发生什么?一些丑陋的Servlet Exception被发送回浏览器或其他一些我认为不友好的结果。
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.
我怀疑从UI / servlet角度区分问题的确切原因通常是有用的,无论是NullPointer,ArrayIndex,OutOfMemory还是其他什么。只是由EJB表示的“服务”失败,可能是因为编码或基础结构错误。用户不能做很多事情,因此对我来说没有特殊的等级。