Catch<TException> 类

定义

包含在相应活动的 Try 块 Finally 中引发异常后要执行的操作。

generic <typename TException>
 where TException : Exceptionpublic ref class Catch sealed : System::Activities::Statements::Catch
[System.Windows.Markup.ContentProperty("Action")]
public sealed class Catch<TException> : System.Activities.Statements.Catch where TException : Exception
[<System.Windows.Markup.ContentProperty("Action")>]
type Catch<'Exception (requires 'Exception :> Exception)> = class
    inherit Catch
Public NotInheritable Class Catch(Of TException)
Inherits Catch

类型参数

TException

块正在处理的异常 Catch<TException> 类型。

继承
Catch<TException>
属性

示例

下面的代码示例演示如何创建 Catch<TException> 活动。 此示例来自 使用 TryCatch 示例的流程图活动中的错误处理

FlowStep mwkStep = new FlowStep
{
    Action = new TryCatch
    {
        DisplayName = "Try/Catch for Divide By Zero Exception",
        Try = new Assign
        {
            DisplayName = "discount = 15 + (1 - 1/numberOfKids)*10",
            To = new OutArgument<double>(discount),
            Value = new InArgument<double>((ctx) => (15 + (1 - 1 / numberOfKids.Get(ctx)) * 10))
        },
        Catches =
        {
             new Catch<System.DivideByZeroException>
             {
                 Action = new ActivityAction<System.DivideByZeroException>
                 {
                     Argument = ex,
                     DisplayName = "ActivityAction - DivideByZeroException",
                     Handler =
                         new Sequence
                         {
                             DisplayName = "Divide by Zero Exception Workflow",
                             Activities =
                             {
                                new WriteLine()
                                {
                                    DisplayName = "WriteLine: DivideByZeroException",
                                    Text = "DivideByZeroException: Promo code is MWK - but number of kids = 0"
                                },
                                new Assign<double>
                                {
                                    DisplayName = "Exception - discount = 0",
                                    To = discount,
                                    Value = new InArgument<double>(0)
                                }
                             }
                         }
                 }
             }
        }
    },
    Next = flowDecision
};

注解

放置在设计器中后, Catch 无法在设计器中重新排序活动。 若要对活动集合 Catch 进行重新排序,请删除并按正确的顺序重新添加活动,或使用工作流的 xaml(代码)视图。

构造函数

名称 说明
Catch<TException>()

创建类的新实例 Catch<TException>

属性

名称 说明
Action

正在捕获异常的处理程序。

ExceptionType

块正在处理的异常 Catch 类型。

方法

名称 说明
Equals(Object)

确定指定的对象是否等于当前对象。

(继承自 Object)
GetHashCode()

用作默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
ToString()

返回一个表示当前对象的字符串。

(继承自 Object)

适用于