public virtual void BeginFinallyBlock() { if (this.m_currExcStackCount == 0) { throw new NotSupportedException(Environment.GetResourceString("Argument_NotInExceptionBlock")); } __ExceptionInfo info = this.m_currExcStack[this.m_currExcStackCount - 1]; int currentState = info.GetCurrentState(); Label endLabel = info.GetEndLabel(); int endCatchAddr = 0; if (currentState != 0) { this.Emit(OpCodes.Leave, endLabel); endCatchAddr = this.m_length; } this.MarkLabel(endLabel); Label lbl = this.DefineLabel(); info.SetFinallyEndLabel(lbl); this.Emit(OpCodes.Leave, lbl); if (endCatchAddr == 0) { endCatchAddr = this.m_length; } info.MarkFinallyAddr(this.m_length, endCatchAddr); }
public override void BeginCatchBlock(Type exceptionType) { if (base.CurrExcStackCount == 0) { throw new NotSupportedException(Environment.GetResourceString("Argument_NotInExceptionBlock")); } __ExceptionInfo info = base.CurrExcStack[base.CurrExcStackCount - 1]; if (info.GetCurrentState() == 1) { if (exceptionType != null) { throw new ArgumentException(Environment.GetResourceString("Argument_ShouldNotSpecifyExceptionType")); } this.Emit(OpCodes.Endfilter); } else { if (exceptionType == null) { throw new ArgumentNullException("exceptionType"); } if (!exceptionType.GetType().IsRuntimeType) { throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType")); } Label endLabel = info.GetEndLabel(); this.Emit(OpCodes.Leave, endLabel); base.UpdateStackSize(OpCodes.Nop, 1); } info.MarkCatchAddr(this.ILOffset, exceptionType); info.m_filterAddr[info.m_currentCatch - 1] = this.m_scope.GetTokenFor(exceptionType.TypeHandle); }
public virtual void BeginCatchBlock(Type exceptionType) { if (this.m_currExcStackCount == 0) { throw new NotSupportedException(Environment.GetResourceString("Argument_NotInExceptionBlock")); } __ExceptionInfo info = this.m_currExcStack[this.m_currExcStackCount - 1]; if (info.GetCurrentState() == 1) { if (exceptionType != null) { throw new ArgumentException(Environment.GetResourceString("Argument_ShouldNotSpecifyExceptionType")); } this.Emit(OpCodes.Endfilter); } else { if (exceptionType == null) { throw new ArgumentNullException("exceptionType"); } Label endLabel = info.GetEndLabel(); this.Emit(OpCodes.Leave, endLabel); } info.MarkCatchAddr(this.m_length, exceptionType); }
public virtual void BeginFaultBlock() { if (this.m_currExcStackCount == 0) { throw new NotSupportedException(Environment.GetResourceString("Argument_NotInExceptionBlock")); } __ExceptionInfo info = this.m_currExcStack[this.m_currExcStackCount - 1]; Label endLabel = info.GetEndLabel(); this.Emit(OpCodes.Leave, endLabel); info.MarkFaultAddr(this.m_length); }
public override void BeginCatchBlock(Type exceptionType) { if (CurrExcStackCount == 0) { throw new NotSupportedException(SR.Argument_NotInExceptionBlock); } Contract.EndContractBlock(); __ExceptionInfo current = CurrExcStack[CurrExcStackCount - 1]; RuntimeType rtType = exceptionType as RuntimeType; if (current.GetCurrentState() == __ExceptionInfo.State_Filter) { if (exceptionType != null) { throw new ArgumentException(SR.Argument_ShouldNotSpecifyExceptionType); } this.Emit(OpCodes.Endfilter); current.MarkCatchAddr(ILOffset, null); } else { // execute this branch if previous clause is Catch or Fault if (exceptionType == null) { throw new ArgumentNullException(nameof(exceptionType)); } if (rtType == null) { throw new ArgumentException(SR.Argument_MustBeRuntimeType); } Label endLabel = current.GetEndLabel(); this.Emit(OpCodes.Leave, endLabel); // if this is a catch block the exception will be pushed on the stack and we need to update the stack info UpdateStackSize(OpCodes.Nop, 1); current.MarkCatchAddr(ILOffset, exceptionType); // this is relying on too much implementation details of the base and so it's highly breaking // Need to have a more integrated story for exceptions current.m_filterAddr[current.m_currentCatch - 1] = GetTokenFor(rtType); } }
public override void BeginCatchBlock(Type exceptionType) { if (m_currExcStackCount == 0) { throw new NotSupportedException(Environment.GetResourceString("Argument_NotInExceptionBlock")); } __ExceptionInfo current = m_currExcStack[m_currExcStackCount - 1]; if (current.GetCurrentState() == __ExceptionInfo.State_Filter) { if (exceptionType != null) { throw new ArgumentException(Environment.GetResourceString("Argument_ShouldNotSpecifyExceptionType")); } this.Emit(OpCodes.Endfilter); } else { // execute this branch if previous clause is Catch or Fault if (exceptionType == null) { throw new ArgumentNullException("exceptionType"); } if (exceptionType.GetType() != typeof(RuntimeType)) { throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType")); } Label endLabel = current.GetEndLabel(); this.Emit(OpCodes.Leave, endLabel); // if this is a catch block the exception will be pushed on the stack and we need to update the stack info UpdateStackSize(OpCodes.Nop, 1); } current.MarkCatchAddr(m_length, exceptionType); // this is relying on too much implementation details of the base and so it's highly breaking // Need to have a more integreted story for exceptions current.m_filterAddr[current.m_currentCatch - 1] = m_scope.GetTokenFor(exceptionType.TypeHandle); }
// // // Exception related generation // // public override void BeginExceptFilterBlock() { // Begins an exception filter block. Emits a branch instruction to the end of the current exception block. if (CurrExcStackCount == 0) { throw new NotSupportedException(SR.Argument_NotInExceptionBlock); } __ExceptionInfo current = CurrExcStack[CurrExcStackCount - 1]; Label endLabel = current.GetEndLabel(); Emit(OpCodes.Leave, endLabel); UpdateStackSize(OpCodes.Nop, 1); current.MarkFilterAddr(ILOffset); }
public virtual void EndExceptionBlock() { if (this.m_currExcStackCount == 0) { throw new NotSupportedException(Environment.GetResourceString("Argument_NotInExceptionBlock")); } __ExceptionInfo info = this.m_currExcStack[this.m_currExcStackCount - 1]; this.m_currExcStack[this.m_currExcStackCount - 1] = null; this.m_currExcStackCount--; Label endLabel = info.GetEndLabel(); switch (info.GetCurrentState()) { case 1: case 0: throw new InvalidOperationException(Environment.GetResourceString("Argument_BadExceptionCodeGen")); case 2: this.Emit(OpCodes.Leave, endLabel); break; case 3: case 4: this.Emit(OpCodes.Endfinally); break; } if (this.m_labelList[endLabel.GetLabelValue()] == -1) { this.MarkLabel(endLabel); } else { this.MarkLabel(info.GetFinallyEndLabel()); } info.Done(this.m_length); }