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

Sun Microsystems Inc.

Exception handling

Enterprise JavaBeans 2.0, Public Draft

Bean Provider’s responsibilities

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 (see Subsections 9.6.8 and 11.1.9). These exceptions are covered by the rules on application exceptions that are defined in this chapter.

17.1.2 Goals for exception handling

The EJB specification for exception handling is designed to meet these high-level goals:

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. 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.

17.2Bean Provider’s responsibilities

This section describes the view and responsibilities of the Bean Provider with respect to exception handling.

17.2.1 Application exceptions

The Bean Provider defines the application exceptions in the throws clauses of the methods of the remote and home interfaces. Because application exceptions are intended to be handled by the client, and not by the system administrator, they should be used only for reporting business logic exceptions, not for reporting system level problems.

The Bean Provider is responsible for throwing the appropriate application exception from the business method to report a business logic exception to the client. Because the application exception does not automatically result in marking the transaction for rollback, the Bean Provider must do one of the following to ensure data integrity before throwing an application exception from an enterprise bean instance:

Ensure that the instance is in a state such that a client’s attempt to continue and/or commit the transaction does not result in loss of data integrity. For example, the instance throws an application exception indicating that the value of an input parameter was invalid before the instance performed any database updates.

Mark the transaction for rollback using the EJBContext.setRollbackOnly() method before throwing an application exception. Marking the transaction for rollback will ensure that the transaction can never commit.

5/31/00

342