public static TryExpression MakeTry(Type type, Expression body, Expression @finally, Expression fault, IEnumerable<CatchBlock> handlers)
{
RequiresCanRead(body, nameof(body));
ReadOnlyCollection<CatchBlock> @catch = handlers.ToReadOnly();
ContractUtils.RequiresNotNullItems(@catch, nameof(handlers));
ValidateTryAndCatchHaveSameType(type, body, @catch);
if (fault != null)
{
if (@finally != null || @catch.Count > 0)
{
throw Error.FaultCannotHaveCatchOrFinally(nameof(fault));
}
RequiresCanRead(fault, nameof(fault));
}
else if (@finally != null)
{
RequiresCanRead(@finally, nameof(@finally));
}
else if (@catch.Count == 0)
{
throw Error.TryMustHaveCatchFinallyOrFault();
}
return new TryExpression(type ?? body.Type, body, @finally, fault, @catch);
}