Dear all, Another question about why an application exception is thrown by a business method won't make container kill the bean, but if the exception is thrown by ejbXX() methods, container will do it? Thanks again!
The application exception is regarded as expected and have to be handled by the invoker. As the invoker expect the exception the exception is supposed to be handled more gracefully than by just kill the bean. The system exception is not expected and seen as something that there is nothing to do anything about. In that case the container tries to limit the damage as much as possible by killing the bean. /Magnus
Hi Magnus, Thanks for your instant reply. But I still have something that I cannot understand. Is an application exception a kind of runtime exceptions or compiled exceptions? Besides, I don't know if system exception are runtime ones or the other ones? Thanks again. Kuo-Feng
Hey Kuo-Feng Sun, Application exceptions are always checked exceptions. These are exceptions that the client expects to happen and can deal with. Checked exceptions must be either caught or thrown and the compiler will always ensure this. Some examples are CreateException, FinderException and RemoveException. A bean provider can also define his own application exceptions by extending Exception or one of the checked exceptions except for RemoteException. System exceptions are always runtime exceptions, except for RemoteException which is a checked exception. System exceptions indicate that something unrecoverable happened on the server. The compiler will not check for handling of these exceptions. If the container recieves a runtime exception from a bean it will rethrow it to a remote client as a RemoteException or to a local client as an EJBException. The container will also rollback the transaction, log the exception and kill the bean. Some examples of runtime exceptions related to EJBs are NoSuchObjectException, TransactionRequiredException and IllegalStateException. Refer to Head First EJB for a more in-depth coverage of exceptions. Hope this helps. [ January 29, 2004: Message edited by: Keith Rosenfield ] [ January 29, 2004: Message edited by: Keith Rosenfield ]