TryExpression 클래스

정의

try/catch/finally/fault 블록을 나타냅니다.

public ref class TryExpression sealed : System::Linq::Expressions::Expression
public sealed class TryExpression : System.Linq.Expressions.Expression
type TryExpression = class
    inherit Expression
Public NotInheritable Class TryExpression
Inherits Expression
상속
TryExpression

예제

다음 예제에서는 메서드를 사용하여 TryCatch catch 문이 포함된 개체를 만드는 TryExpression 방법을 보여 줍니다.

// Add the following directive to the file:
// using System.Linq.Expressions;

// A TryExpression object that has a Catch statement.
// The return types of the Try block and all Catch blocks must be the same.
TryExpression tryCatchExpr =
    Expression.TryCatch(
        Expression.Block(
            Expression.Throw(Expression.Constant(new DivideByZeroException())),
            Expression.Constant("Try block")
        ),
        Expression.Catch(
            typeof(DivideByZeroException),
            Expression.Constant("Catch block")
        )
    );

// The following statement first creates an expression tree,
// then compiles it, and then runs it.
// If the exception is caught,
// the result of the TryExpression is the last statement
// of the corresponding Catch statement.
Console.WriteLine(Expression.Lambda<Func<string>>(tryCatchExpr).Compile()());

// This code example produces the following output:
//
// Catch block
' Add the following directive to the file:
' Imports System.Linq.Expressions 

' A TryExpression object that has a Catch statement.
' The return types of the Try block and all Catch blocks must be the same.
Dim tryCatchExpr As TryExpression =
       Expression.TryCatch(
           Expression.Block(
               Expression.Throw(Expression.Constant(New DivideByZeroException())),
               Expression.Constant("Try block")
           ),
           Expression.Catch(
               GetType(DivideByZeroException),
               Expression.Constant("Catch block")
           )
       )

' The following statement first creates an expression tree,
' then compiles it, and then runs it.
' If the exception is caught, 
' the result of the TryExpression is the last statement 
' of the corresponding Catch statement.
Console.WriteLine(Expression.Lambda(Of Func(Of String))(tryCatchExpr).Compile()())

' This code example produces the following output:
'
' Catch block

설명

본문 블록은 try 블록으로 보호됩니다.

처리기는 catch 문 또는 필터일 수 있는 식 집합 CatchBlock 으로 구성됩니다.

예외가 throw되면 오류 블록이 실행됩니다.

마지막으로 블록은 컨트롤이 본문을 종료하는 방법에 관계없이 실행됩니다.

오류 또는 최종 블록 중 하나만 제공할 수 있습니다.

try 블록의 반환 형식은 연결된 catch 문의 반환 형식과 일치해야 합니다.

속성

Body

try 블록의 본문을 나타내는 Expression을 가져옵니다.

CanReduce

노드를 더 단순한 노드로 줄일 수 있는지 나타냅니다. true를 반환하면 Reduce()를 호출하여 축소된 형식을 만들 수 있습니다.

(다음에서 상속됨 Expression)
Fault

fault 블록을 나타내는 Expression을 가져옵니다.

Finally

finally 블록을 나타내는 Expression을 가져옵니다.

Handlers

try 블록에 연결된 CatchBlock 식의 컬렉션을 가져옵니다.

NodeType

Expression의 노드 유형을 반환합니다.

Type

Expression이 나타내는 식의 정적 형식을 가져옵니다.

메서드

Accept(ExpressionVisitor)

이 노드 형식에 대한 특정 Visit 메서드로 디스패치합니다. 예를 들어 MethodCallExpressionVisitMethodCall(MethodCallExpression)을 호출합니다.

(다음에서 상속됨 Expression)
Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
Reduce()

이 노드를 더 단순한 식으로 줄입니다. CanReduce가 true를 반환하면 유효한 식을 반환합니다. 이 메서드는 자체를 줄여야 하는 다른 노드를 반환할 수 있습니다.

(다음에서 상속됨 Expression)
ReduceAndCheck()

이 노드를 더 단순한 식으로 줄입니다. CanReduce가 true를 반환하면 유효한 식을 반환합니다. 이 메서드는 자체를 줄여야 하는 다른 노드를 반환할 수 있습니다.

(다음에서 상속됨 Expression)
ReduceExtensions()

알려진 노드 형식(확장 노드가 아님)으로 식을 줄이거나 이미 알려진 형식인 경우 식을 반환합니다.

(다음에서 상속됨 Expression)
ToString()

Expression의 텍스트 표현을 반환합니다.

(다음에서 상속됨 Expression)
Update(Expression, IEnumerable<CatchBlock>, Expression, Expression)

제공된 자식을 사용하여 이 식과 같은 새 식을 만듭니다. 모든 자식이 같으면 이 식을 반환합니다.

VisitChildren(ExpressionVisitor)

노드를 줄인 다음 줄인 식에서 방문자 대리자를 호출합니다. 이 메서드는 노드를 줄일 수 없으면 예외를 throw합니다.

(다음에서 상속됨 Expression)

적용 대상