What can go wrong?

  1. In the Bean

    • The business logic in a method realizes that it cannot do its job because of a problem the client expects. For example, a banking bean can’t do a balance transfer, because the ‘transfer from’ account doesn’t have any money!

    • The bean catches a checked exception while running business logic. For example, the bean fails to get a JDBC connection, or a JNDI lookup throws a NamingException to the bean. This is a problem that the bean expects, but the client doesn’t.

    • A method in the bean (or a method the bean calls) throws a runtime exception (like NullPointerException) that the bean doesn’t catch, and the client doesn’t expect.

  2. In the Container

    • The Container can’t complete an operation for which its responsible, such as updating the state of an entity bean in the database, that causes a problem the client expects.

    • The Container catches a checked exception thrown by the bean, that the client expects.

    • A Container catches a runtime exception thrown by the bean, or by some other object the Container interacts with. This is a problem that the client does not expect.

  3. In the RMI subsystem, or some other part of the communication path between client and container.

    • The EJB object throws a runtime exception before it communicates with the client about the result of a client’s business method call to the bean.

    • The RMI subsystem can’t communicate with the client.

    • The client stub throws a runtime exception, or a RemoteException while trying to send a method call, or receive a return ...

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.