コード例 #1
0
        /// <summary>
        /// Raises an exception, throwing 'ex' as an IodineException object
        /// </summary>
        /// <param name="ex">Exception to raise.</param>
        public void RaiseException(IodineObject ex)
        {
            if (traceCallback != null)
            {
                traceCallback(TraceType.Exception, this, Top, currentLocation);
            }

            IodineExceptionHandler handler = PopCurrentExceptionHandler();

            if (handler == null)   // No exception handler

            /*
             * The program has gone haywire and we ARE going to crash, however
             * we must attempt to properly dispose any objects created inside
             * Iodine's with statement
             */
            {
                StackFrame top = Top;
                while (top != null)
                {
                    while (top.DisposableObjects.Count > 0)
                    {
                        IodineObject obj = top.DisposableObjects.Pop();
                        try {
                            obj.Exit(this);  // Call __exit__
                        } catch (UnhandledIodineExceptionException) {
                            // Ignore this, we will throw one when we're done anyway
                        }
                    }
                    top = top.Parent;
                }
                throw new UnhandledIodineExceptionException(Top, ex);
            }

            ex.SetAttribute("stacktrace", new IodineString(GetStackTrace()));

            UnwindStack(frameCount - handler.Frame);
            lastException          = ex;
            Top.InstructionPointer = handler.InstructionPointer;
        }