1 Reply Latest reply on Sep 23, 2009 6:01 AM by Wolfgang Knauf

    Checked exception thrown from injected stateless bean become

    Tvrtko S Newbie

      I have a stateless bean injected by container. When called, this bean throws a checked exception (Failure). But the exception that caller catches is runtime exception (IllegalStateException).

      Here is a short example:

      class Failure extends Exception {
       ...
      }
      
      @Local
      public interface OutputQueueHandler {
       public void handle(...) throws Failure;
      }
      
      @Stateless
      public class OutputQueueHandlerBean implements OutputQueueHandler {
      
       @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
       public void handle(...) throws Failure {
       try {
       ...
       persistError('ACK'); // 1.A
       throw new Failure(); // 1.B
       ...
       }
       catch (RuntimeException e) {
       throw new Failure(e);
       }
       }
      }
      
      @MessageDriven(...)
      @Depends(...)
      public class OutputQueueMDB implements MessageListener {
      
       @EJB
       OutputQueueHandler outputQueueHandler;
      
       public void onMessage(javax.jms.Message message) {
       ...
       try {
       outputQueueHandler.handle(...); // 2
       }
       catch (RuntimeException e) {
       persistError('HANDLE'); // 3
       }
       ...
       }
      }
      


      I have read somewhere that it is OK to throw checked exceptions. All I can find now is http://www.devx.com/Java/Article/30496/1763/page/3 (search for text "Exception Handling")

      Is it because the bean method is annotated with TransactionAttributeType.REQUIRES_NEW?

      How can I get my original exception?

      My environment is JBoss 4.2.1 GA with EJB 3.0

      Thanks,
      Tvrtko