DCSIMG
Windows Workflow Compensation and Fault Handling - Guy Burstein's Blog

Guy Burstein's Blog

Developer Evangelist @ Microsoft

News

Guy Burstein The Bu

Disclaimer
Postings are provided 'As Is' with no warranties and confer no rights.

Guy Burstein LinkedIn Profile

TwitterCounter for @bursteg

Links

Articles

Blogs I Read

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.

Comments

Guy Burstein's Blog said:

This is my #200 post, and it is a good time to look back at what I've posted over the last few months.

# March 9, 2007 8:48 PM

K. Scott Allen said:

Due to popular demand, here are some answers to the questions. Well, not answers exactly ... just...

# November 1, 2007 3:13 AM

BusinessRx Reading List said:

Due to popular demand, here are some answers to the questions . Well, not answers exactly ... just some

# November 1, 2007 3:53 AM

nick_outrol said:

# June 30, 2009 12:02 PM

nick_delric said:

# June 30, 2009 12:04 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: