[jboss-user] [EJB 3.0 Users] - Checked exception thrown from injected stateless bean become

tvrtko do-not-reply at jboss.com
Tue Sep 22 13:10:22 EDT 2009


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

View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4256470#4256470

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4256470



More information about the jboss-user mailing list