According to the Spec it says that IllegalStateException must be thrown but the container implementation might throw and more general Exception than the specific one, so it might throw a RemoteException/EJBException.I am confused for the same reason, if the exam question gives both the generic and the specific Exception as optinos,which one must be chosen?
Joined: Sep 27, 2004
Maybe this helps:
IllegalStateException is thrown by the container to the *bean* (eg if the bean code makes a call to getUserTransaction() that is not allowed).
If the bean code doesn't handle the exception the container will throw a RemoteException/EJBException to the client.
I think the above is true, though someone in this forum somewhere recently said the exception to this was TransactionRolledBackException and it's local version. Can anybody tidy all this up to give an overall set of rules?
An application exception is an exception that is declared to be thrown by the home/component method that is a (indirect) subclass of Exception but not of RuntimeException (+ some exceptions to this rule, see spec).
So: - runtime exceptions like IllegalStateException and NullpointerException can never be application exceptions and the container will always throw Remote/EJBException when the bean throws such an exception. - system exceptions may be re-thrown to the client, but only if they are explicitly included in the throws clause of the home/component interface - If a bean method makes a call to a remote interface, any RemoteExceptions or subclasses thereof thrown from the remote method must be handled by the bean code because bean methods are not allowed to throw RemoteExceptions - If a bean method makes a call to a local interface and the bean code doesn’t handle EJBExceptions or subclasses thereof : the container is required to throw a Remote/EJBException. I suppose that in the case of a local interface the container could just re-throw the exception, but I don’t think it is required to do so.
I remember some one saying Container may throw Generic Exceptions instead of Specific Exception like CreateException instead of DuplicateKeyException. But that is certainly not applicable in the above mentioned case.
So to summarize it let me say:
System exceptions are wrapped in RemoteException and client receives RemoteException even if system exception is mentioned in throws clause of a method of a bean.
Regards,<br />Sandesh<br />(SCJCP, SCWCD, SCBCD - 99%, OCP-1)<br /> <br />Either find a way or create one.
Joined: Sep 29, 2004
Thank you for correcting me: I got the terminolgy mixed up.
- system exceptions may be re-thrown to the client, but only if they are explicitly included in the throws clause of the home/component interface
- checked exceptions are re-thrown to the client, but only if they are explicitly included in the throws clause of the home/component interface
just wanted to add one line here that exceptions local to the bean like SQLExceptions and others of similar nature should be avoided in throws clause of Home/Compnt Iface as they hold no meaning to the client.
This approach should be avoided even for debugging purposes.
All such exception should lead to throwing a EJBException/Remoteexception only.
Rahul Devgan<br />SCJP<br />--- one must be willing to let go of small pleasures in life to achieve greater things ---