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 } ... } }
Hi,
I think the "javax.ejb.ApplicationException" annotation might help:
http://java.sun.com/javaee/5/docs/api/javax/ejb/ApplicationException.html
Best regards
Wolfgang