EJB3.1系统异常vs javax.ejb.EJBException [英] EJB3.1 System Exceptions vs javax.ejb.EJBException
问题描述
应用程序例外包含
-
具有
@ApplicationException注释的用户定义的已检查或未检查的异常 -
所有检查的异常
java.lang.Exception&它是子类异常
除了java.rmi.RemoteException&它是子类异常
系统异常包括
-
java.rmi.RemoteException,它是子类异常
-
所有未选中的异常
java.lang.RuntimeException,它是子类异常
java.lang.Error,它是子类异常
以下是我在此书籍中阅读的声明
在EJB中系统异常不被客户端例外,遇到这样的异常并不像客户端那样传递给客户端,而是在javax.ejb.EJBException中被包装。 / p>
我的问题 -
- 上面提到的异常应该由EJB直接抛出给客户端?
- 如果系统异常在抛出客户端之前被包含在javax.ejb.EJBException中,那么是java x.ejb.EJBException被视为系统异常?
- 是的,或多或少是他们的工作方式。有关EJB行为的更多详细信息,请查看以下博文:链接
同样从这个问题:
应用程序异常有一个
的业务逻辑错误,而不是系统错误时抛出。
有一个重要的区别:应用程序异常不
自动导致事务回滚。客户端有一个
机会在抛出应用程序异常后恢复。
将应用程序异常发送到客户端,而不需要重新打包
作为EJBException 。因此,您可以使用它们来报告验证
错误或业务逻辑问题,他们将到达客户端。
-
javax.ejb.EJBException
extendsRuntimeException
所以是的,这是一个系统异常
与此相关联的常见方案:如果您没有收到 RuntimeException
在您的应用程序代码中将会回滚。这是非常有用的默认行为。
Just a bit of background on EJB3.1 exceptions before bringing up my question -
Application exceptions comprise of
User defined checked or unchecked exceptions which have @ApplicationException annotation
All checked exceptions
java.lang.Exception & it's subclass exceptions
except java.rmi.RemoteException & it's subclass exceptions
System exceptions comprise of
java.rmi.RemoteException and it's subclass exceptions
All unchecked exceptions
java.lang.RuntimeException and it's subclass exceptions
java.lang.Error and it's subclass exceptions
Below is a statement I have read in this book
In EJB System exceptions are not excepted by the client, when encountered such exceptions are not passed to the client as is but are wrapaped in a javax.ejb.EJBException.
My questions -
- Are all application exceptions described above supposed to be thrown directly by EJB to client?
- If System Exceptions are wrapped inside javax.ejb.EJBException before throwing to the client, then is javax.ejb.EJBException considered as System Exception?
- Yes, more or less that's how they work. For further details on EJB's behaviors check out the following blog post: Link
Also from this question:
An application exception shall be thrown when there is a business-logic error, as opposed to a system error.
There is an important difference: application exceptions do not automatically cause a transaction to rollback. The client has an opportunity to recover after an application exception is thrown.
Application exceptions are sent to the client without being repackaged as an EJBException. Therefore, you can use them to report validation errors or business logic problems, and they will reach the client.
javax.ejb.EJBException
extendsRuntimeException
so yes, it is a System Exception.
Common scenario associated with this: if you've got an uncaught RuntimeException
in your application code it will roll-back. It's pretty useful default behavior.
这篇关于EJB3.1系统异常vs javax.ejb.EJBException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!