Exceptions in client interfaces: what the client might get
A Remote interface must have RemoteException declared on every method. That means the client using a Remote interface must deal with RemoteException for every Remote method call. But local interfaces don’t have that restriction. The only methods in a local client interface that must declare exceptions are the create() and remove() methods (for session beans; entity beans also have a finder method that declares a FinderException).
We have a whole chapter devoted to exceptions in EJB, so we won’t go into the details now, but the essence is this: if a bean (or the Container) generates a runtime exception, Remote clients see the exception as a checked RemoteException, but local clients see it as an unchecked EJBException.
In addition to whatever other checked exceptions (called application exceptions in EJB) the interface methods declare, all Remote interface methods can throw a RemoteException and local client interface methods can always throw an EJBException. So Remote clients must wrap all calls to a home or component interface method in a try/catch, while local clients use a try/catch only if the interface method declares an application exception (which includes CreateException, RemoveException, FinderException, and any other exceptions the Bean Provider declares in the methods of the bean’s client interfaces).
lndicates a ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access