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);
     }
 }
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;
                    }
                }
            }
        }