Chapter 10.  Exceptions

Identify correct and incorrect statements or examples about exception handling in EJB.


An application exception is an exception defined by the Bean Provider as part of the business logic of an application. Application exceptions are distinguished from system exceptions in EJB 3.0 specification.

Enterprise bean business methods use application exceptions to inform the client of abnormal application-level conditions, such as unacceptable values of the input arguments to a business method. A client can typically RECOVER from an application exception. Application exceptions are NOT intended for reporting system-level problems.

For example, the Account enterprise bean may throw an application exception to report that a debit operation cannot be performed because of an insufficient balance. The Account bean should not use an application exception to report, for example, the failure to obtain a database connection.

An application exception MAY be defined in the throws clause of a method of an enterprise bean's business interface, home interface, component interface, message listener interface, or web service endpoint.

An application exception MAY be a subclass (direct or indirect) of java.lang.Exception (i.e., a "checked exception"), or an application exception class may be defined as a subclass of the java.lang.RuntimeException (an "unchecked exception"). An application exception MAY NOT be a subclass of the java.rmi.RemoteException. The java.rmi.RemoteException and its subclasses are RESERVED for system exceptions.

The javax.ejb.CreateException, javax.ejb.RemoveException, javax.ejb.FinderException, and subclasses thereof are considered to be application exceptions. These exceptions are used as standard application exceptions to report errors to the client from the create, remove, and finder methods of the EJBHome and/or EJBLocalHome interfaces of components written to the EJB 2.1 client view.

Goals for Exception Handling

  • An application exception thrown by an enterprise bean instance should be reported to the client PRECISELY (i.e., the client gets the SAME exception).

  • An application exception thrown by an enterprise bean instance should NOT automatically rollback a client's transaction unless the application exception was defined to cause transaction rollback. The client should typically be given a chance to recover a transaction from an application exception.

  • An unexpected exception that may have left the instance's state variables and/or underlying persistent data in an inconsistent state can be handled safely.

Professional hosting     Belorussian informational portal         Free SCWCD 1.4 Study Guide     Free SCDJWS 1.4 Study Guide     SCDJWS 1.4 Quiz     Free IBM Certified Associate Developer Study Guide     IBM Test 000-287. Enterprise Application Development with IBM WebSphere Studio, V5.0 Study Guide     Free Mock Exam Engine