Windows Workflow Compensation and Fault Handling
Windows Workflow Foundation provides a rich set of features to support powerful fault handling, robust Atomic and long-running transactions, and flexible compensation support for failed transactions.
Causing an Exception
There are several ways to generate an exception:
· A transaction time-out.
· An exception thrown by the workflow using the ThrowActivity activity.
· A .NET Framework exception thrown from the developer code handlers of the CodeActivity or code-beside of custom activities.
· An exception thrown from external code, such as libraries or components that are used in the workflow (Persistence failure).
Fault Handling
Fault handling in Windows Workflow Foundation refers to the handling of exceptions in an asynchronous manner. This means that exceptions that are thrown in an activity (explicitly or implicitly) are caught by the workflow runtime engine and then scheduled to be handled at a later time. This differs from normal exception handling in that if an exception is thrown in a try block, it is either caught by the appropriate catch exception block, or it is thrown to the user immediately.
The activity that threw the exception cannot handle it. The exception is transferred up the workflow hierarchy until it is either handled, or the workflow instance is terminated by the workflow runtime engine. When the exception is handled inside the workflow, the handling section goal is to do the partial and unsuccessful work of the activity in which an exception has occurred.
To handle an exception in a workflow, use the FaultHandlerActivity, and a set the type of the exception it handles (Similar to catch exception block). This activity is a composite activity and can contain a sequence of activities to execute in case that the exception has occurred.
All FaultHandlers are childs of a FaultHandlersActivity.

Compensation vs. Fault Handling
A typical scenario for compensation handling would be when an activity successfully completes, but an exception is thrown in another activity later in the workflow. Different than Fault Handling, we now want to cancel the completed work and not to undo any partial and unsuccessful work of the activity in which an exception has occurred.
The triggering of a compensation block is done by the workflow designer, and not only by the workflow runtime. This is done using the CompensateActivity.