RemoteException goes to remote clients EJBException goes to local clients

When something unexpected happens on the server, the Container tells the client by throwing either a RemoteException or an EJBException.

RemoteException is for remote clients only, and even though it is a checked exception, it’s telling the client that something unexpected happened. Something from which the client can’t recover.

EJBException is for local clients only, and it’s unchecked. In other words, EJBException is a subclass of RuntimeException. To the client, getting an EJBException isn’t much different from getting, say, an ArrayIndexOutOfBoundsException. It means something unexpected went wrong, and there’s nothing you can do to recover. The only difference is that the client does have to catch the RemoteException, but once he catches it, the client usually won’t be able to tell what happened (at least not in any recoverable way).

When something unexpected happens on the server, a local client gets a RuntimeException (EJBException) but a remote client gets a compiler-checked RemoteException

Remote client

image with no caption

Local client

image with no caption

Get Head First EJB now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.