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);
        }
Exemple #2
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;
                    }
                }
            }
        }