System.Linq.Expressions.Expression.MakeCatchBlock C# (CSharp) Method

MakeCatchBlock() public static method

Creates a CatchBlock representing a catch statement with the specified elements.
type must be non-null and match the type of variable (if it is supplied).
public static MakeCatchBlock ( Type type, System.Linq.Expressions.ParameterExpression variable, Expression body, Expression filter ) : CatchBlock
type Type The of this will handle.
variable System.Linq.Expressions.ParameterExpression A representing a reference to the object caught by this handler.
body Expression The body of the catch statement.
filter Expression The body of the filter.
return CatchBlock
        public static CatchBlock MakeCatchBlock(Type type, ParameterExpression variable, Expression body, Expression filter)
        {
            ContractUtils.RequiresNotNull(type, nameof(type));
            ContractUtils.Requires(variable == null || TypeUtils.AreEquivalent(variable.Type, type), nameof(variable));
            if (variable == null)
            {
                TypeUtils.ValidateType(type, nameof(type));
                if (type.IsByRef)
                {
                    throw Error.TypeMustNotBeByRef(nameof(type));
                }

                if (type.IsPointer)
                {
                    throw Error.TypeMustNotBePointer(nameof(type));
                }
            }
            else if (variable.IsByRef)
            {
                throw Error.VariableMustNotBeByRef(variable, variable.Type, nameof(variable));
            }
            RequiresCanRead(body, nameof(body));
            if (filter != null)
            {
                RequiresCanRead(filter, nameof(filter));
                if (filter.Type != typeof(bool)) throw Error.ArgumentMustBeBoolean(nameof(filter));
            }

            return new CatchBlock(type, variable, body, filter);
        }
    }
Expression