Reputation: 14456
The following code:
try {
value = parse(myData);
} catch (Exception e) {
if ( e instanceof IOException|| e instanceof IllegalArgumentException) {
logger.debug("illegal argument");
} else {
logger.debug("this is printing");
}
}
Parse method:
parse(String data) throws IOException, IllegalArgumentException {
// do validation
throw new IllegalArgumentException("illegal");
}
I was expecting "Illegal argument". But instead it shows "this is printing".
Did I miss anything here?
Upvotes: 2
Views: 2630
Reputation: 1
Yes you are right. IllegalArgumentException is wrapped by EJBTransactionRollbackException. I had same problem, when i use JsrValidator inside EJB Bean. This is happened because a RuntimeException was thrown inside EJB Bean, and AOP wraps it.If you too use EJB bean in parse method, try to add try-catch there.
Upvotes: 0
Reputation: 14456
I traced it. When this IllegalArgumentException is thrown, its wrapped by EJBTransactionRollbackException.
The following is thrown:
The transaction has been marked rollback only because the bean encountered a non-application
exception :java.lang.IllegalArgumentException:
Actual Exception class: class javax.ejb.EJBTransactionRolledbackException
Now the question is different, how not to have EJBTransactionException override the actual exception
Upvotes: 2
Reputation: 41
Just an idea. Are you sure you use classes from the same package on throw and catch sections. For example you can throw com.foo.bar.IllegalArgumentException
in parse method but trying to catch java.lang.IllegalArgumentException
So could you please check import section in case you have them in different classes.
Upvotes: 0