// MakeTry: the one factory that creates TryStatement
public static TryExpression MakeTry(Expression body, Expression @finally, Expression fault, IEnumerable <CatchBlock> handlers)
{
RequiresCanRead(body, "body");
var @catch = handlers.ToReadOnly();
ContractUtils.RequiresNotNullItems(@catch, "handlers");
if (fault != null)
{
if (@finally != null || @catch.Count > 0)
{
throw Error.FaultCannotHaveCatchOrFinally();
}
RequiresCanRead(fault, "fault");
}
else if (@finally != null)
{
RequiresCanRead(@finally, "finally");
}
else if (@catch.Count == 0)
{
throw Error.TryMustHaveCatchFinallyOrFault();
}
return(new TryExpression(body, @finally, fault, @catch));
}