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);
}
}