# Faults, Compensation, Termination and Event Handlers

Handlers allow a BPEL process to recover from exception conditions. Exception conditions include: a timeout waiting for a response from a partner service, invalid or missing message data, a fault condition returned by a service. There are four types of handlers:

- Fault handler : Executed when a fault is thrown by an activity.
- Compensation handler : Executed when the BPEL process encounters a Compensate or CompensateScope activity.
- Termination handler : Executed if a Scope is forced to terminate early.
- Event handler : Executed for events include the receipt of a message and a timer expiration.

Handlers are defined for the process or for certain activities. To create a new handler right-click an activity and select the desired handler from its context menu. The BPEL Designer will generate a skeleton of the handler within a collapsible window that is attached to the activity. The figure below illustrates all of the different types of handlers in their fully expanded view. The handler windows can be collapsed and expanded by clicking on their respective icon.

Handlers overview

The behavior of handlers and the order of exception processing is complex and beyond the scope of this document. Refer to the OASIS WS-BPEL 2.0 specification at http://docs.oasis-open.org/wsbpel/2.0/wsbpel-v2.0.html for more information.

##### Process-level Handlers

Start activity with handlers

Fault and event handlers can be defined for the process by right-clicking the Start activity and selecting the desired handler from the context menu.

##### Scope-level handlers

A Scope may have any handler. Since Scopes can be nested, each level can define its own set of handlers. Events that are not caught and processed by a handler in an inner Scope, will be propagated to its ancestors.

##### Activity-level handlers

Only the Invoke activity can define handlers. The handlers available to it are the fault and compensation handlers.