Also, specifically he says:
An application exception must never extend either the RuntimeException, the RemoteException, or one of their subtypes.
An application exception is normally thrown in response to a business-logic error, as opposed to a system error. Application exceptions are always delivered directly to the client, without being repackaged as RemoteException or EJBException (EJB 2.0) types. They do not typically cause transactions to roll back; the client usually has an opportunity to recover after an application exception is thrown
This sample session bean code from the JONAS project throws RemoteExceptions from its business methods for every type of errors it encounters e.g. null parameter, inability to persist.
Q1) Is this the correct use of RemoteException ? I'd thought that Bean developers should not throw SystemExceptions (RuntimeExceptions etc.. and also RemoteExceptions) ?
Q2) When should we (BeanDevelopers) use ApplicationExceptions (checked exceptions) ?
If I understand this correctly, I can throw ApplicationExceptions right before any calls to the DB. Because after that point, a transaction would have been started.
The bean method should throw the appropriate application exception to report a business logic exception to the client. It does not automatically result in marking the transaction for rollback because the client is expected to be able to recover from it.
If the bean method throws a checked exception that the bean method cannot recover, the bean method should encapsulate the exception in javax.ejb.EJBException (which is then thrown to the container).
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koophttps://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton