Fault Handler Activity

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 in a queue 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.

 

Use the FaultHandler Activity to Handle Exceptions

 

There are two ways you can handle exceptions in a workflow. The first is to use a try-catch block in your code. The try-catch block enables you to handle exceptions in the code that caused the exception. You can then write additional code to take an action. The second way to handle exceptions is to use the FaultHandler activity. This activity handles a specific fault type and enables you to execute workflow activities in response to an exception. You can use these activities to perform cleanup and recovery.

 

You can associate a FaultHandler activity with the workflow itself or with any container activity in the workflow (with the exception of the TransactionScope and CompensatableTransactionScope activities). You will now add a FaultHandler activity to the workflow to handle the file not found exception as follows:

 

Navigate to any Workflow Activity where you want to add FaultHandlerActivity>> Expand the Arrow icon>> Select View Fault Handlers option from the list as shown below:

 

fault handlers-1.zoom75
Click on image to magnify/shrink

 

You can drag and drop the FaultHandlerActivity in the grid as shown below.

 

fault handlers-2.zoom75
Click on image to magnify/shrink

 

Thereafter, you should see following icon for Fault Handler Activity. Right side of the window shows the Properties associated with FaultHandlerActivity.

 

fault handlers-3.zoom70
Click on image to magnify/shrink