Пример #1
0
        internal static int FindMatchingHandler(MutableTuple tuple, RuntimeException rte, Type[] types, ExecutionContext context)
        {
            Exception replaceParentContainsErrorRecordException = rte;
            Exception innerException = rte.InnerException;
            int       index          = -1;

            if (innerException != null)
            {
                index = FindMatchingHandlerByType(innerException.GetType(), types);
                replaceParentContainsErrorRecordException = innerException;
            }
            if ((index == -1) || types[index].Equals(typeof(CatchAll)))
            {
                index = FindMatchingHandlerByType(rte.GetType(), types);
                replaceParentContainsErrorRecordException = rte;
            }
            if ((index == -1) || types[index].Equals(typeof(CatchAll)))
            {
                ActionPreferenceStopException exception3 = rte as ActionPreferenceStopException;
                if (exception3 != null)
                {
                    replaceParentContainsErrorRecordException = exception3.ErrorRecord.Exception;
                    if (replaceParentContainsErrorRecordException is RuntimeException)
                    {
                        return(FindMatchingHandler(tuple, (RuntimeException)replaceParentContainsErrorRecordException, types, context));
                    }
                    if (replaceParentContainsErrorRecordException != null)
                    {
                        index = FindMatchingHandlerByType(replaceParentContainsErrorRecordException.GetType(), types);
                    }
                }
                else if ((rte is CmdletInvocationException) && (innerException != null))
                {
                    replaceParentContainsErrorRecordException = innerException.InnerException;
                    if (replaceParentContainsErrorRecordException != null)
                    {
                        index = FindMatchingHandlerByType(replaceParentContainsErrorRecordException.GetType(), types);
                    }
                }
            }
            if (index != -1)
            {
                ErrorRecord record = new ErrorRecord(rte.ErrorRecord, replaceParentContainsErrorRecordException);
                tuple.SetAutomaticVariable(AutomaticVariable.Underbar, record, context);
            }
            return(index);
        }
Пример #2
0
        private static ActionPreference ProcessTraps(FunctionContext funcContext, RuntimeException rte)
        {
            int       index = -1;
            Exception replaceParentContainsErrorRecordException = null;
            Exception innerException = rte.InnerException;

            Type[] types = funcContext._traps.Last <Tuple <Type[], Action <FunctionContext>[], Type[]> >().Item1;
            Action <FunctionContext>[] actionArray = funcContext._traps.Last <Tuple <Type[], Action <FunctionContext>[], Type[]> >().Item2;
            if (innerException != null)
            {
                index = FindMatchingHandlerByType(innerException.GetType(), types);
                replaceParentContainsErrorRecordException = innerException;
            }
            if ((index == -1) || types[index].Equals(typeof(CatchAll)))
            {
                int num2 = FindMatchingHandlerByType(rte.GetType(), types);
                if (num2 != index)
                {
                    index = num2;
                    replaceParentContainsErrorRecordException = rte;
                }
            }
            if (index != -1)
            {
                try
                {
                    ErrorRecord      errorRecord = rte.ErrorRecord;
                    ExecutionContext context     = funcContext._executionContext;
                    if (context.CurrentCommandProcessor != null)
                    {
                        context.CurrentCommandProcessor.ForgetScriptException();
                    }
                    try
                    {
                        MutableTuple tuple = MutableTuple.MakeTuple(funcContext._traps.Last <Tuple <Type[], Action <FunctionContext>[], Type[]> >().Item3[index], Compiler.DottedLocalsNameIndexMap);
                        tuple.SetAutomaticVariable(AutomaticVariable.Underbar, new ErrorRecord(errorRecord, replaceParentContainsErrorRecordException), context);
                        for (int i = 1; i < 9; i++)
                        {
                            tuple.SetValue(i, funcContext._localsTuple.GetValue(i));
                        }
                        SessionStateScope scope = context.EngineSessionState.NewScope(false);
                        context.EngineSessionState.CurrentScope = scope;
                        scope.LocalsTuple = tuple;
                        FunctionContext context2 = new FunctionContext {
                            _scriptBlock      = funcContext._scriptBlock,
                            _sequencePoints   = funcContext._sequencePoints,
                            _executionContext = funcContext._executionContext,
                            _boundBreakpoints = funcContext._boundBreakpoints,
                            _outputPipe       = funcContext._outputPipe,
                            _breakPoints      = funcContext._breakPoints,
                            _localsTuple      = tuple
                        };
                        actionArray[index](context2);
                    }
                    catch (TargetInvocationException exception3)
                    {
                        throw exception3.InnerException;
                    }
                    finally
                    {
                        context.EngineSessionState.RemoveScope(context.EngineSessionState.CurrentScope);
                    }
                    return(QueryForAction(rte, replaceParentContainsErrorRecordException.Message, context));
                }
                catch (ContinueException)
                {
                    return(ActionPreference.SilentlyContinue);
                }
                catch (BreakException)
                {
                    return(ActionPreference.Stop);
                }
            }
            return(ActionPreference.Stop);
        }
Пример #3
0
 private static ActionPreference ProcessTraps(FunctionContext funcContext, RuntimeException rte)
 {
     int index = -1;
     Exception replaceParentContainsErrorRecordException = null;
     Exception innerException = rte.InnerException;
     Type[] types = funcContext._traps.Last<Tuple<Type[], Action<FunctionContext>[], Type[]>>().Item1;
     Action<FunctionContext>[] actionArray = funcContext._traps.Last<Tuple<Type[], Action<FunctionContext>[], Type[]>>().Item2;
     if (innerException != null)
     {
         index = FindMatchingHandlerByType(innerException.GetType(), types);
         replaceParentContainsErrorRecordException = innerException;
     }
     if ((index == -1) || types[index].Equals(typeof(CatchAll)))
     {
         int num2 = FindMatchingHandlerByType(rte.GetType(), types);
         if (num2 != index)
         {
             index = num2;
             replaceParentContainsErrorRecordException = rte;
         }
     }
     if (index != -1)
     {
         try
         {
             ErrorRecord errorRecord = rte.ErrorRecord;
             ExecutionContext context = funcContext._executionContext;
             if (context.CurrentCommandProcessor != null)
             {
                 context.CurrentCommandProcessor.ForgetScriptException();
             }
             try
             {
                 MutableTuple tuple = MutableTuple.MakeTuple(funcContext._traps.Last<Tuple<Type[], Action<FunctionContext>[], Type[]>>().Item3[index], Compiler.DottedLocalsNameIndexMap);
                 tuple.SetAutomaticVariable(AutomaticVariable.Underbar, new ErrorRecord(errorRecord, replaceParentContainsErrorRecordException), context);
                 for (int i = 1; i < 9; i++)
                 {
                     tuple.SetValue(i, funcContext._localsTuple.GetValue(i));
                 }
                 SessionStateScope scope = context.EngineSessionState.NewScope(false);
                 context.EngineSessionState.CurrentScope = scope;
                 scope.LocalsTuple = tuple;
                 FunctionContext context2 = new FunctionContext {
                     _scriptBlock = funcContext._scriptBlock,
                     _sequencePoints = funcContext._sequencePoints,
                     _executionContext = funcContext._executionContext,
                     _boundBreakpoints = funcContext._boundBreakpoints,
                     _outputPipe = funcContext._outputPipe,
                     _breakPoints = funcContext._breakPoints,
                     _localsTuple = tuple
                 };
                 actionArray[index](context2);
             }
             catch (TargetInvocationException exception3)
             {
                 throw exception3.InnerException;
             }
             finally
             {
                 context.EngineSessionState.RemoveScope(context.EngineSessionState.CurrentScope);
             }
             return QueryForAction(rte, replaceParentContainsErrorRecordException.Message, context);
         }
         catch (ContinueException)
         {
             return ActionPreference.SilentlyContinue;
         }
         catch (BreakException)
         {
             return ActionPreference.Stop;
         }
     }
     return ActionPreference.Stop;
 }
Пример #4
0
 internal static int FindMatchingHandler(MutableTuple tuple, RuntimeException rte, Type[] types, ExecutionContext context)
 {
     Exception replaceParentContainsErrorRecordException = rte;
     Exception innerException = rte.InnerException;
     int index = -1;
     if (innerException != null)
     {
         index = FindMatchingHandlerByType(innerException.GetType(), types);
         replaceParentContainsErrorRecordException = innerException;
     }
     if ((index == -1) || types[index].Equals(typeof(CatchAll)))
     {
         index = FindMatchingHandlerByType(rte.GetType(), types);
         replaceParentContainsErrorRecordException = rte;
     }
     if ((index == -1) || types[index].Equals(typeof(CatchAll)))
     {
         ActionPreferenceStopException exception3 = rte as ActionPreferenceStopException;
         if (exception3 != null)
         {
             replaceParentContainsErrorRecordException = exception3.ErrorRecord.Exception;
             if (replaceParentContainsErrorRecordException is RuntimeException)
             {
                 return FindMatchingHandler(tuple, (RuntimeException) replaceParentContainsErrorRecordException, types, context);
             }
             if (replaceParentContainsErrorRecordException != null)
             {
                 index = FindMatchingHandlerByType(replaceParentContainsErrorRecordException.GetType(), types);
             }
         }
         else if ((rte is CmdletInvocationException) && (innerException != null))
         {
             replaceParentContainsErrorRecordException = innerException.InnerException;
             if (replaceParentContainsErrorRecordException != null)
             {
                 index = FindMatchingHandlerByType(replaceParentContainsErrorRecordException.GetType(), types);
             }
         }
     }
     if (index != -1)
     {
         ErrorRecord record = new ErrorRecord(rte.ErrorRecord, replaceParentContainsErrorRecordException);
         tuple.SetAutomaticVariable(AutomaticVariable.Underbar, record, context);
     }
     return index;
 }