1 Reply Latest reply on Apr 17, 2007 6:46 PM by cracru

    Should unchecked, but declared exceptions get wrapped in EJB

    cracru

      Should unchecked, but declared exceptions get wrapped in EJBException?

      The spec is a little vague on the subject.

      It would seem logical and beneficial to have any unchecked exception that is explicitly stated in the throws clause of a business method be considered an application exception, and not wrapped in an EJBException.

      The current behavior in 4.0.5 seems to be to wrap in an EJBException, all unchecked exceptions thrown that are not directly annotated with @ApplicationException, or are not included in an application-exception deployment element.

        • 1. Re: Should unchecked, but declared exceptions get wrapped in
          cracru

          The spec lead at Sun was kind enough to answer my question. Here's the results:

          Of course, the JBoss implementation is operating per design and spec.

          This means, all unchecked (and extending RuntimeException) exceptions that are not in the control of the business method developer, should not be included in the throws clause of a business method.

          For example, don't do this in the SLSB:

          public void findWidget (Integer widgetId)
           throws javax.persistence.EntityNotFoundException
          


          Doing so, makes for a confusing contract with the client. In the example the EntityNotFoundException will be treated as a system exception and wrapped with EJBException before it is passed to the client.

          If you own the exception, you can annotate with @ApplicationException. Otherwise, you have two choices:

          - catch, wrap, and throw your own exception
          - use application-exception deployment descriptor to affect all occurrences of the exception