Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Enterprise JavaBeans™ Specification, v1.1 - Sun Microsystems.pdf
Скачиваний:
11
Добавлен:
24.05.2014
Размер:
1.62 Mб
Скачать

Sun Microsystem Inc

Client’s view of exceptions

Enterprise JavaBeans v1.1, Final Release

Exception handling

Note: The use of the java.rmi.RemoteException is deprecated only in the above-mentioned methods. The methods of the remote and home interface still must use the java.rmi.RemoteException as required by the EJB specification.

12.4 Client’s view of exceptions

This section describes the client’s view of exceptions received from an enterprise bean invocation.

A client accesses an enterprise Bean through the enterprise Bean’s remote and home interfaces. Both of these interfaces are Java RMI interfaces, and therefore the throws clauses of all their methods (including those inherited from superinterfaces) include the mandatory java.rmi.RemoteException.The throws clauses may include an arbitrary number of application exceptions.

12.4.1 Application exception

If a client program receives an application exception from an enterprise bean invocation, the client can continue calling the enterprise bean. An application exception does not result in the removal of the EJB object.

If a client program receives an application exception from an enterprise bean invocation while the client is associated with a transaction, the client can typically continue the transaction because an application exception does not automatically causes the Container to mark the transaction for rollback.

For example, if a client receives the ExceedLimitException application exception from the debit method of an Account bean, the client may invoke the debit method again, possibly with a lower debit amount parameter. If the client executed in a transaction context, throwing the ExceedLimitException exception would not automatically result in rolling back, or marking for rollback, the client’s transaction.

Although the Container does not automatically mark for rollback a transaction because of a thrown application exception, the transaction might have been marked for rollback by the enterprise bean instance before it threw the application exception. There are two ways to learn if a particular application exception results in transaction rollback or not:

Statically. Programmers can check the documentation of the enterprise bean’s remote or home interface. The Bean Provider may have specified (although he is not required to) the application exceptions for which the enterprise bean marks the transaction for rollback before throwing the exception.

Dynamically. Clients that are enterprise beans with container-managed transaction demarcation can use the getRollbackOnly() method of the javax.ejb.EJBContext object to learn if the current transaction has been marked for rollback; other clients may use the getStatus() method of the javax.transaction.UserTransaction interface to obtain the transaction status.

195

11/24/99