In EJB, exceptions come in two flavors: application and system

Application exceptions are things the client expects, which means the client has to handle them one way or another. This means that application exceptions are declared in the interfaces exposed to the client, and the client uses a try/catch when she calls the method. Since the client can catch the expected exception, the client might be able to recover and keep going. Application exceptions include things like CreateException (maybe the client-supplied arguments weren’t valid), or AccountBalanceException (perhaps the client can try a different account with the next call), or ObjectNotFoundException (that entity is no longer in the database). Application exceptions include all checked exceptions thrown by a bean or a Container, except java.rmi.RemoteException. Although RemoteException is checked, and the client catches it, as far as the client is concerned, whatever caused the RemoteException on the server was unexpected.

System exceptions are for things the client does not expect and/or can’t recover from. This could be virtually any runtime exception that happens on the server (from the bean or the Container or any other object on the server), or even in the client’s local stub object. System exceptions are things the client really can’t recover from, either because they’re not recoverable (like a failure in the database or a NullPointerException) or because the client doesn’t have enough information to know what to ...

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.