WWF transaction and exception handling activities <Part 4>

Source: Internet
Author: User
I. faulthandler

The following figure shows how to add a workflow:

  

First, add a seruence, add three codes in it, add a code outside, enable seruence error handling, add a faulthandler in the container, and add a code activity in faulthandler.

  

  

Set the faultType attribute of faulthandler as follows:

  

  

  

Be sure to bind the property.

Running effect:

  

Note that if faulthandler captures errors, other code activities in seruence will not be executed, but the code outside seruence will continue to be executed.

Ii. Throw

In the WWF workflow, throw can also throw an exception with specific information. Similar to the throw of C. You can declare an explicit exception in the workflow through the throw activity and throw it. When an exception occurs, the "workflowterminated" event of the container runtime when the workflow is running is triggered.

Create a workflow as follows:

  

Set the faultType attribute of the throw activity as follows:

  

The Code is as follows:

Public sealed partial class workflow1: sequentialworkflowactivity {public workflow1 () {initializecomponent ();} private void code1 (Object sender, eventargs e) {console. writeline ("code1 execution... "); console. readkey ();} private void code2 (Object sender, eventargs e) {console. writeline ("caught \" try to divide by 0 \ "exception ");}}

The output is as follows:

  

If the sequence container does not capture exceptions, it is easy that the subsequent codeacticity1 activity will not be executed.

Iii. Compensate

In actual work, the workflow also needs to process the business logic in some special circumstances. For example, if an email is sent incorrectly, It is not deleted by logging on to the customer's mailbox, instead, send another email to inform the user of the error.

In WWF, you can use the compensatablesequence activity and compensatable activity.

Like a faulthandler activity, compensation also needs to specify a region. If exceptions occur in this region, compensatable can be used to specify the region in which the exception type should be compensated. The compensatablesequence activity can be used in this region. The compensatablesequence activity is an easy sequence type, similar to the sequence activity.

Example: If a mode user sends a parcel to a purchased item, and the delivery delay may be caused by weather during transportation, the compensation process will be started to notify the buyer.

WWF transaction and exception handling activities <Part 4>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.