user manual

210 BES Developers Guide
Handling of EJB exceptions
errors, transcend the application itself and can be handled by the application,
the bean, or the bean container.
The EJB declares application-level exceptions and system-level exceptions in
the throws clauses of its Home and Remote interfaces. You must check for
checked exceptions in your program try/catch block when calling bean
methods.
System-level exceptions
An EJB throws a system-level exception, which is a java.ejb.EJBException (but
may also be a java.rmi.RemoteException), to indicate an unexpected system-
level failure. For example, it throws this exception if it cannot open a database
connection. The java.ejb.EJBException is a runtime exception and does not
have to be listed in the throws clause of the bean's business methods.
System-level exceptions usually require the transaction to be rolled back.
Often, the container managing the bean does the rollback. Other times,
especially with bean-managed transactions, the client must rollback the
transaction.
Application-level exceptions
An EJB throws an application-level exception to indicate application-specific
error conditions, that is, business logic errors and not system problems. These
application-level exceptions are exceptions other than java.ejb.EJBException.
Application-level exceptions are checked exceptions, which means you must
check for them when you call a method that potentially can throw this
exception.
The EJB's business methods use application exceptions to report abnormal
application conditions, such as unacceptable input values or amounts beyond
acceptable limits. For example, a bean method that debits an account balance
can throw an application exception to report that the account balance is not
sufficient to permit a particular debit operation. A client can often recover from
these application-level errors without having to rollback the entire transaction.
The application or calling program gets back the same exception that was
thrown and this allows the calling program to know the precise nature of the
problem. When an application-level exception occurs, the EJB instance does
not automatically rollback the client's transaction. The client now has the
knowledge and the opportunity to evaluate the error message, take the
necessary steps to correct the situation, and recover the transaction.
Otherwise, the client can abort the transaction.
Handling application exceptions
Because application-level exceptions report business logic errors, the client is
expected to handle these exceptions. While these exceptions can require