I call account
EJB method in JSF bean like that :
try{
account.someFunction(...);
}catch(SimRuntimeException e){
logger.log(Level.FATAL, "SimRuntimeException catched !");
}catch(SimNotRuntimeException e){
logger.log(Level.FATAL, "SimNotRuntimeException catched !");
}catch(Exception e){
logger.log(Level.FATAL, "Exception catched !");
}
My Exceptions :
public class SimRuntimeException extends RuntimeException {
public SimRuntimeException() {
super();
}
}
@ApplicationException(rollback=true)
public class SimNotRuntimeException extends Exception {
public SimNotRuntimeException() {
super();
}
}
account.someFunction(...);
throws SimRuntimeException
I fall
into Exception
block because my SimRuntimeException
is wrapped
into EJBException
probably by EJB container.account.someFunction(...);
throws SimNotRuntimeException
I fall as expected
into SimNotRuntimeException
So, what is concretely the difference between Exception
with @ApplicationException(rollback=true)
and RuntimeException
please ?
Pal's blog states:
EJB makes a difference in Application Exceptions and System Exceptions. Application exception is something that you define, you throw, and you are aware of. By default the application exception does not cause a rollback, unless you define it that way (and I think it's recommended). Every checked exception that is mentioned in the method signature and also any checked or unchecked exception that is annotated with @ApplicationException, is an application exception.
System exceptions happen in cases, you don't control, and they are unchecked exceptions. They always cause rollback. Good practice is, if you wrap checked exceptions -- that cannot be avoided -- in your method into EJBException e.g. ParseException.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With