public override void VisitProtect(ProtectStatement protect)
{
exceptionLevel++;
ilGenerator.BeginExceptionBlock();
protect.StatementList.Accept(this);
foreach (ProtectWhen when in protect.WhenPartList) {
ilGenerator.BeginCatchBlock(when.TypeSpecifier.RawType);
LocalBuilder prevException = currentException;
currentException =
ilGenerator.DeclareLocal(when.TypeSpecifier.RawType);
ilGenerator.Emit(OpCodes.Stloc, currentException);
when.ThenPart.Accept(this);
currentException = prevException;
}
if (protect.ElsePart != null) {
ilGenerator.BeginCatchBlock(typeof(Exception));
LocalBuilder prevException = currentException;
currentException =
ilGenerator.DeclareLocal(typeof(Exception));
ilGenerator.Emit(OpCodes.Stloc, currentException);
protect.ElsePart.Accept(this);
currentException = prevException;
}
ilGenerator.EndExceptionBlock();
exceptionLevel--;
}