コード例 #1
0
ファイル: ExceptionHandling.cs プロジェクト: RobertiF/Dynamo
        /// <summary>
        /// Walking through the exception handler chain to find the proper 
        /// exception handler. Also notify the observers who are keen on being 
        /// notified when an exception is happening. 
        /// </summary>
        /// <param name="context">Exception context</param>
        public void HandleFirstHandException(ExceptionContext context)
        {
            ExceptionHandler exceHandler = ExceptionTable.FindExceptionHandler(context);
            if (exceHandler != null)
            {
                TargetHandler = exceHandler;
            }
            Context = context;
            IsStackUnwinding = true;

            // Anybody wants to be notified before going to exception handler
            // or stack unwinding?
            foreach (IFirstHandExceptionObserver observer in Observers)
            {
                observer.Notify(context);
            }
        }
コード例 #2
0
ファイル: ExceptionHandling.cs プロジェクト: RobertiF/Dynamo
        /// <summary>
        /// Walk through chained exception registration instances to find out
        /// the corresponding exception handler. Returns null if cannot find
        /// the handler.
        /// </summary>
        /// <param name="context">Exception context</param>
        /// <returns></returns>
        public ExceptionHandler FindExceptionHandler(ExceptionContext context)
        {
            int regIndex = IndexOf(context.codeBlockId, context.functionScope, context.classScope);
            Validity.Assert(regIndex != ProtoCore.DSASM.Constants.kInvalidIndex);

            ExceptionRegistration registration = Registrations[regIndex];
            int pc = context.pc;
            while (true)
            {
                int handlerIndex;
                if (registration.HandleIt(pc, context.typeUID, out handlerIndex))
                {
                    Validity.Assert(handlerIndex != ProtoCore.DSASM.Constants.kInvalidIndex);
                    return registration.Handlers[handlerIndex];
                }
                else
                {
                    int parentIndex = registration.ParentIndex;
                    if (parentIndex == ProtoCore.DSASM.Constants.kInvalidIndex)
                    {
                        break;
                    }
                    else
                    {
                        pc = registration.LastPc;
                        registration = Registrations[parentIndex];
                    }
                }
            }
            return null;
        }