本文介绍了EJB3.1系统异常vs javax.ejb.EJBException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



应用程序例外包含




  • 具有
    @ApplicationException注释的用户定义的已检查或未检查的异常


  • 所有检查的异常



    java.lang.Exception&它是子类异常

    除了java.rmi.RemoteException&它是子类异常




系统异常包括




  • java.rmi.RemoteException,它是子类异常


  • 所有未选中的异常



    java.lang.RuntimeException,它是子类异常

    java.lang.Error,它是子类异常




以下是我在此中阅读的声明

我的问题 -


  1. 上面提到的异常应该由EJB直接抛出给客户端?

  2. 如果系统异常在抛出客户端之前被包含在javax.ejb.EJBException中,那么是java x.ejb.EJBException被视为系统异常?


解决方案

  1. 是的,或多或少是他们的工作方式。有关EJB行为的更多详细信息,请查看以下博文:

同样从这个:




  1. javax.ejb.EJBException extends RuntimeException 所以是的,这是一个系统异常

与此相关联的常见方案:如果您没有收到 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

My questions -

  1. Are all application exceptions described above supposed to be thrown directly by EJB to client?
  2. If System Exceptions are wrapped inside javax.ejb.EJBException before throwing to the client, then is javax.ejb.EJBException considered as System Exception?
解决方案
  1. 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:

  1. javax.ejb.EJBException extends RuntimeException 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 17:56