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
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
In the SQL Query Analyzer workspace, select the database that you created in step 1 in the list of available databases.
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.
Execute the query by clicking Execute or by pressing F5 to create the SQL Persistence Service tables.
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.
Execute the query by clicking Execute or by pressing F5 to create the SQL Persistence Service stored procedures.
To build the sample
Download the sample by clicking Download Sample in this topic.
This extracts the sample project to your local hard disk.
Click Start, point to Programs, point to Microsoft Windows SDK, and then click CMD Shell.
Go to the source directory of the sample.
At the command prompt, type MSBUILD <Solution file name>.
To run the sample
- 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..