public override void CloseScope(ILBuilder builder) { Debug.Assert(this.handlers.Count > 1); // Fix up the NextExceptionHandler reference of each leader block. var tryScope = this.handlers[0]; var previousBlock = tryScope.LeaderBlock; for (int i = 1; i < this.handlers.Count; i++) { var handlerScope = this.handlers[i]; var nextBlock = handlerScope.LeaderBlock; previousBlock.NextExceptionHandler = nextBlock; previousBlock = nextBlock; } // Generate label for try/catch "leave" target. builder.MarkLabel(this.endLabel); // hide the following code, since it could be reached through the label above. builder.DefineHiddenSeqPoint(); Debug.Assert(builder.currentBlock == builder.labelInfos[this.endLabel].bb); if (this.handlers[1].Type == ScopeType.Finally) { // Generate "nop" branch to itself. If this block is unreachable // (because the finally block does not complete), the "nop" will be // replaced by Br_s. On the other hand, if this block is reachable, // the "nop" will be skipped so any "leave" instructions jumping // to this block will jump to the next instead. builder.EmitBranch(ILOpCode.Nop, this.endLabel); this.handlers[1].SetBlockedByFinallyDestination(this.endLabel); } }