System.Reflection.Emit.DynamicILGenerator.BeginCatchBlock C# (CSharp) Method

BeginCatchBlock() public method

public BeginCatchBlock ( Type exceptionType ) : void
exceptionType System.Type
return void
        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);
        }