Esempio n. 1
0
        private void ExecuteStatement(
            ParseTreeNode statement,
            Array input,
            Pipe outputPipe,
            ref ArrayList resultList,
            ExecutionContext context)
        {
            ScriptTrace.TraceLine(context, statement);
            Exception e = (Exception)null;

            try
            {
                try
                {
                    if (statement.IsVoidable)
                    {
                        statement.Execute(input, (Pipe)null, context);
                    }
                    else
                    {
                        statement.Execute(input, outputPipe, ref resultList, context);
                    }
                    ParseTreeNode parseTreeNode = statement;
                    while (parseTreeNode is AssignmentStatementNode assignmentStatementNode)
                    {
                        parseTreeNode = assignmentStatementNode.RightHandSide;
                    }
                    if (parseTreeNode.IsExpression)
                    {
                        context.QuestionMarkVariableValue = true;
                    }
                    else if (parseTreeNode is PipelineNode pipelineNode)
                    {
                        context.QuestionMarkVariableValue = !pipelineNode.ExecutionFailed(context);
                    }
                }
                catch (COMException ex)
                {
                    throw InterpreterError.NewInterpreterExceptionWithInnerException((object)null, typeof(RuntimeException), statement.NodeToken, "COMException", (Exception)ex, (object)ex.Message);
                }
                catch (InvalidComObjectException ex)
                {
                    throw InterpreterError.NewInterpreterExceptionWithInnerException((object)null, typeof(RuntimeException), statement.NodeToken, "InvalidComObjectException", (Exception)ex, (object)ex.Message);
                }
            }
            catch (ReturnException ex)
            {
                if (resultList == null || resultList.Count == 0)
                {
                    e = (Exception)ex;
                }
                else
                {
                    ParseTreeNode.AppendResult(context, ex.Argument, (Pipe)null, ref resultList);
                    ex.SetArgument((object)resultList.ToArray());
                    resultList = (ArrayList)null;
                    e          = (Exception)ex;
                }
            }
            catch (RuntimeException ex)
            {
                e = this.HandleException(statement.NodeToken, ex, outputPipe, ref resultList, context);
            }
            if (e != null)
            {
                RuntimeException.LockStackTrace(e);
                throw e;
            }
        }
Esempio n. 2
0
        internal static void CheckActionPreference(FunctionContext funcContext, Exception exception)
        {
            ActionPreference preference;

            if (exception is TargetInvocationException)
            {
                exception = exception.InnerException;
            }
            CommandProcessorBase.CheckForSevereException(exception);
            RuntimeException exception2 = exception as RuntimeException;

            if (exception2 == null)
            {
                exception2 = ConvertToRuntimeException(exception, funcContext.CurrentPosition);
            }
            else
            {
                InterpreterError.UpdateExceptionErrorRecordPosition(exception2, funcContext.CurrentPosition);
            }
            RuntimeException.LockStackTrace(exception2);
            ExecutionContext context        = funcContext._executionContext;
            Pipe             outputPipe     = funcContext._outputPipe;
            IScriptExtent    scriptPosition = exception2.ErrorRecord.InvocationInfo.ScriptPosition;

            SetErrorVariables(scriptPosition, exception2, context, outputPipe);
            context.QuestionMarkVariableValue = false;
            bool flag = funcContext._traps.Any <Tuple <Type[], Action <FunctionContext>[], Type[]> >() && (funcContext._traps.Last <Tuple <Type[], Action <FunctionContext>[], Type[]> >().Item2 != null);

            if (!flag && !NeedToQueryForActionPreference(exception2, context))
            {
                throw exception2;
            }
            if (flag)
            {
                preference = ProcessTraps(funcContext, exception2);
            }
            else
            {
                preference = QueryForAction(exception2, exception2.Message, context);
            }
            context.QuestionMarkVariableValue = false;
            switch (preference)
            {
            case ActionPreference.SilentlyContinue:
            case ActionPreference.Ignore:
                return;

            case ActionPreference.Stop:
                exception2.SuppressPromptInInterpreter = true;
                throw exception2;
            }
            if (!flag && exception2.WasThrownFromThrowStatement)
            {
                throw exception2;
            }
            bool flag2 = ReportErrorRecord(scriptPosition, exception2, context);

            context.QuestionMarkVariableValue = false;
            if (!flag2)
            {
                throw exception2;
            }
        }