posted 18 years ago
Furthermore, you have to decide how the exception will be handled by the session bean.
1. If it is a RuntimeException like IllegalArgumentException, do nothing - just let it propogate to the container.
2. If it is a exception such as SQLException which the client is not expecting, then this sort of exception must be encapsulated in a javax.ejb.EJBException and thrown to the container.
In both these cases, the container will:
Throw a system exception (java.rmi.RemoteException to a remote client or javax.ejb.EJBException to a local client)
Log the exception
Rollback the transaction
Kill the bean instance
3, If it is an exception that the client expects, ie can recover from it, then the bean must throw a (checked) application exception to the container.
If the bean receives an application exception in the first place, then it can be ducked (or handled and rethrown to the container).
If the bean does not receive an application exception, then the bean must create an application exception and throw it to the container.
And remember, both the bean class and the client interface must declare the application exception.
4. If you have an application exception and the transaction cannot continue, then setRollbackOnly() must be called to prevent the transaction from being committed before the application exception is thrown to the container.
SCJP 1.4, SCWCD 1.3, SCBCD 1.3