Ejemplo n.º 1
0
        private ActionPreference ProcessTraps(
            RuntimeException rte,
            Pipe outputPipe,
            ref ArrayList resultList,
            ExecutionContext context)
        {
            ExceptionHandlerNode trap      = (ExceptionHandlerNode)null;
            Exception            exception = (Exception)null;

            if (rte.InnerException != null)
            {
                trap      = ExceptionHandlerNode.GetHandler(this._traps, rte.InnerException, context);
                exception = rte.InnerException;
            }
            if (trap == null)
            {
                trap      = ExceptionHandlerNode.GetHandler(this._traps, (Exception)rte, context);
                exception = (Exception)rte;
            }
            return(trap != null?this.TrapException(trap, rte, exception, outputPipe, ref resultList, context) : ActionPreference.Stop);
        }
Ejemplo n.º 2
0
 private ActionPreference TrapException(
     ExceptionHandlerNode trap,
     RuntimeException runtimeException,
     Exception exception,
     Pipe outputPipe,
     ref ArrayList resultList,
     ExecutionContext context)
 {
     try
     {
         ErrorRecord errorRecord = runtimeException.ErrorRecord;
         trap.Invoke(new ErrorRecord(errorRecord, exception), outputPipe, ref resultList);
         return(this.QueryForAction(runtimeException, exception.Message, context));
     }
     catch (ContinueException ex)
     {
         return(ActionPreference.SilentlyContinue);
     }
     catch (BreakException ex)
     {
         return(ActionPreference.Stop);
     }
 }
Ejemplo n.º 3
0
 internal void Validate(Parser parser)
 {
     if (!this._validated && this._catchBlocks.Count > 1)
     {
         Exception exception = (Exception)null;
         try
         {
             for (int index1 = 0; index1 < this._catchBlocks.Count - 1; ++index1)
             {
                 ExceptionHandlerNode catchBlock1 = this._catchBlocks[index1];
                 for (int index2 = index1 + 1; index2 < this._catchBlocks.Count; ++index2)
                 {
                     ExceptionHandlerNode catchBlock2 = this._catchBlocks[index2];
                     if (catchBlock1.ExceptionTypes == null)
                     {
                         if (parser != null)
                         {
                             parser.ReportException((object)null, typeof(ParseException), catchBlock1.NodeToken, "EmptyCatchNotLast");
                             break;
                         }
                         exception = (Exception)InterpreterError.NewInterpreterException((object)null, typeof(RuntimeException), catchBlock1.NodeToken, "EmptyCatchNotLast");
                         break;
                     }
                     if (catchBlock2.ExceptionTypes != null)
                     {
                         foreach (TypeLiteral exceptionType1 in (Collection <TypeLiteral>)catchBlock1.ExceptionTypes)
                         {
                             Type type1 = exceptionType1.Type;
                             foreach (TypeLiteral exceptionType2 in (Collection <TypeLiteral>)catchBlock2.ExceptionTypes)
                             {
                                 Type type2 = exceptionType2.Type;
                                 if (type1 == type2 || type2.IsSubclassOf(type1))
                                 {
                                     if (parser != null)
                                     {
                                         parser.ReportException((object)null, typeof(ParseException), exceptionType2.Token, "ExceptionTypeAlreadyCaught", (object)type2);
                                     }
                                     else
                                     {
                                         exception = (Exception)InterpreterError.NewInterpreterException((object)null, typeof(RuntimeException), exceptionType2.Token, "ExceptionTypeAlreadyCaught", (object)type2);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         catch (ParseException ex)
         {
             throw;
         }
         catch (RuntimeException ex)
         {
             return;
         }
         if (exception != null)
         {
             throw exception;
         }
     }
     this._validated = true;
 }
Ejemplo n.º 4
0
        internal override void Execute(
            Array input,
            Pipe outputPipe,
            ref ArrayList resultList,
            ExecutionContext context)
        {
            this.CheckForInterrupts(context);
            bool enclosingStatementBlock = context.ExceptionHandlerInEnclosingStatementBlock;

            context.ExceptionHandlerInEnclosingStatementBlock = true;
            try
            {
                this._body.Execute(input, outputPipe, ref resultList, context);
            }
            catch (RuntimeException ex)
            {
                ExceptionHandlerNode exceptionHandlerNode = (ExceptionHandlerNode)null;
                Exception            exception            = ex.InnerException;
                if (exception != null)
                {
                    exceptionHandlerNode = ExceptionHandlerNode.GetHandler(this._catchBlocks, exception, context);
                }
                if (exceptionHandlerNode == null || exceptionHandlerNode.ExceptionTypes == null)
                {
                    exception            = (Exception)ex;
                    exceptionHandlerNode = ExceptionHandlerNode.GetHandler(this._catchBlocks, exception, context);
                }
                if (exceptionHandlerNode != null)
                {
                    Exception exceptionBeingHandled = context.CurrentExceptionBeingHandled;
                    try
                    {
                        context.CurrentExceptionBeingHandled = exception;
                        ErrorRecord errorRecord = ex.ErrorRecord;
                        exceptionHandlerNode.Invoke(new ErrorRecord(errorRecord, exception), outputPipe, ref resultList);
                    }
                    finally
                    {
                        context.CurrentExceptionBeingHandled = exceptionBeingHandled;
                    }
                }
                else
                {
                    throw;
                }
            }
            finally
            {
                context.ExceptionHandlerInEnclosingStatementBlock = enclosingStatementBlock;
                if (this._finally != null)
                {
                    LocalPipeline currentlyRunningPipeline = (LocalPipeline)context.CurrentRunspace.GetCurrentlyRunningPipeline();
                    bool          isStopping = currentlyRunningPipeline.Stopper.IsStopping;
                    currentlyRunningPipeline.Stopper.IsStopping = false;
                    try
                    {
                        this._finally.Execute(input, outputPipe, ref resultList, context);
                    }
                    finally
                    {
                        currentlyRunningPipeline.Stopper.IsStopping = isStopping;
                    }
                }
            }
        }
Ejemplo n.º 5
0
 internal override void Visit(ExceptionHandlerNode node) => this.preOrderNodes.Add((ParseTreeNode)node);
 internal override void Visit(ExceptionHandlerNode node) => this.ReportError((ParseTreeNode)node, "TrapStatementNotSupportedInDataSection");