Nested Exception Handlers Sample

This sample describes how to set and use Windows Workflow Foundation exception handlers. Exceptions provide a structured, uniform, and type-safe way of handling workflow, activity, and user-level error conditions. The exception mechanism in Windows Workflow Foundation is similar to C#. It enables a developer to throw exceptions, catch exceptions by type, and assign exceptions to a variable.

More than one exception handler can be associated with a workflow, or with an activity that enables exception-handler behavior. This enables the developer to have different handler code based on the exception type. Similar to C#, when an exception is thrown, the first exception handler in the call stack that matches the exception type is invoked. For example, if an exception orderException is thrown and there is no exception handling for that type, the exception is evaluated against any exception handlers in the containing activity, and so on, until the workflow level is reached. The workflow terminates after the workflow exception handler is executed, or if no handler is available at the workflow level.

In this sample, the workflow contains a FaultHandlersActivity activity. It is a composite activity that supports exception handling. The SynchronizationScopeActivity activity contains a single CodeActivity activity. The code handler for the CodeActivity activity throws a System.Exception. The FaultHandlersActivity activityhas an exception handler for System.Exception exceptions that will be called to handle this exception.

Using the Sample

To use the sample, you must create the SQL persistence database.

To create the SQL persistence database

  1. Using Microsoft SQL Server 2005 Express, SQL Server 2000 or later versions, or SQL Server 2000 Desktop Engine (MSDE), create a new database named SqlPersistenceService by using the SQL query statement:

    CREATE DATABASE SqlPersistenceService
    

    Note

    When using both the SqlTrackingService and the SqlWorkflowPersistenceService in a workflow application, it is recommended to use a single database for both persistence and tracking.

  2. In the SQL Query Analyzer workspace, select the database that you created in step 1 in the list of available databases.

  3. On the File menu, click Open and open the SQL script %WINDIR%\Microsoft.NET\Framework\v3.0\Windows Workflow Foundation\SQL\<language>\SqlPersistenceService_Schema.sql.

  4. Execute the query by clicking Execute or by pressing F5 to create the SQL Persistence Service tables.

  5. On the File menu, click Open and open the SQL script %WINDIR%\Microsoft.NET\Framework\v3.0\Windows Workflow Foundation\SQL\<language>\SqlPersistenceService_Logic.sql.

  6. Execute the query by clicking Execute or by pressing F5 to create the SQL Persistence Service stored procedures.

To build the sample

  1. Download the sample by clicking Download Sample in this topic.

    This extracts the sample project to your local hard disk.

  2. Click Start, point to Programs, point to Microsoft Windows SDK, and then click CMD Shell.

  3. Go to the source directory of the sample.

  4. At the command prompt, type MSBUILD <Solution file name>.

To run the sample

  1. In the SDK Command Prompt window, run the .exe file in the OutlookWorkflowWizard\bin\debug folder (or the OutlookWorkflowWizard\bin folder for the Visual Basic version of the sample), which is located below the main folder for the sample..

See Also

Tasks

Throw Sample

Reference

FaultHandlersActivity
SynchronizationScopeActivity
CodeActivity

Other Resources

Windows Workflow Foundation Activities
Fault Handling in Workflows
Using the FaultHandlersActivity Activity
Activities Samples
Windows Workflow Foundation Samples

Send comments about this topic to Microsoft.