当前位置: 首页>>代码示例>>C#>>正文


C# InterpretedFrame.SaveTraceToException方法代码示例

本文整理汇总了C#中System.Management.Automation.Interpreter.InterpretedFrame.SaveTraceToException方法的典型用法代码示例。如果您正苦于以下问题:C# InterpretedFrame.SaveTraceToException方法的具体用法?C# InterpretedFrame.SaveTraceToException怎么用?C# InterpretedFrame.SaveTraceToException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Management.Automation.Interpreter.InterpretedFrame的用法示例。


在下文中一共展示了InterpretedFrame.SaveTraceToException方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

 public override int Run(InterpretedFrame frame)
 {
     if (this._hasFinally)
     {
         frame.PushContinuation(base._labelIndex);
     }
     int instructionIndex = frame.InstructionIndex;
     frame.InstructionIndex++;
     Instruction[] instructions = frame.Interpreter.Instructions.Instructions;
     try
     {
         int index = frame.InstructionIndex;
         while ((index >= this._tryHandler.TryStartIndex) && (index < this._tryHandler.TryEndIndex))
         {
             index += instructions[index].Run(frame);
             frame.InstructionIndex = index;
         }
         if (index == this._tryHandler.GotoEndTargetIndex)
         {
             frame.InstructionIndex += instructions[index].Run(frame);
         }
     }
     catch (RethrowException)
     {
         throw;
     }
     catch (Exception exception)
     {
         ExceptionHandler handler;
         frame.SaveTraceToException(exception);
         if (!this._tryHandler.IsCatchBlockExist)
         {
             throw;
         }
         frame.InstructionIndex += this._tryHandler.GotoHandler(frame, exception, out handler);
         if (handler == null)
         {
             throw;
         }
         ThreadAbortException exception2 = exception as ThreadAbortException;
         if (exception2 != null)
         {
             System.Management.Automation.Interpreter.Interpreter.AnyAbortException = exception2;
             frame.CurrentAbortHandler = handler;
         }
         bool flag = false;
         try
         {
             int num3 = frame.InstructionIndex;
             while ((num3 >= handler.HandlerStartIndex) && (num3 < handler.HandlerEndIndex))
             {
                 num3 += instructions[num3].Run(frame);
                 frame.InstructionIndex = num3;
             }
             if (num3 == this._tryHandler.GotoEndTargetIndex)
             {
                 frame.InstructionIndex += instructions[num3].Run(frame);
             }
         }
         catch (RethrowException)
         {
             flag = true;
         }
         if (flag)
         {
             throw;
         }
     }
     finally
     {
         if (this._tryHandler.IsFinallyBlockExist)
         {
             int num4 = frame.InstructionIndex = this._tryHandler.FinallyStartIndex;
             while ((num4 >= this._tryHandler.FinallyStartIndex) && (num4 < this._tryHandler.FinallyEndIndex))
             {
                 num4 += instructions[num4].Run(frame);
                 frame.InstructionIndex = num4;
             }
         }
     }
     return (frame.InstructionIndex - instructionIndex);
 }
开发者ID:nickchal,项目名称:pash,代码行数:82,代码来源:EnterTryCatchFinallyInstruction.cs

示例2: Run

        public override int Run(InterpretedFrame frame)
        {
            Debug.Assert(_tryHandler != null, "the tryHandler must be set already");

            if (_hasFinally)
            {
                // Push finally. 
                frame.PushContinuation(_labelIndex);
            }
            int prevInstrIndex = frame.InstructionIndex;
            frame.InstructionIndex++;

            // Start to run the try/catch/finally blocks
            var instructions = frame.Interpreter.Instructions.Instructions;
            try
            {
                // run the try block
                int index = frame.InstructionIndex;
                while (index >= _tryHandler.TryStartIndex && index < _tryHandler.TryEndIndex)
                {
                    index += instructions[index].Run(frame);
                    frame.InstructionIndex = index;
                }

                // we finish the try block and is about to jump out of the try/catch blocks
                if (index == _tryHandler.GotoEndTargetIndex)
                {
                    // run the 'Goto' that jumps out of the try/catch/finally blocks
                    Debug.Assert(instructions[index] is GotoInstruction, "should be the 'Goto' instruction that jumps out the try/catch/finally");
                    frame.InstructionIndex += instructions[index].Run(frame);
                }
            }
            catch (RethrowException)
            {
                // a rethrow instruction in the try handler gets to run
                throw;
            }
            catch (Exception exception)
            {
                frame.SaveTraceToException(exception);
                // rethrow if there is no catch blocks defined for this try block
                if (!_tryHandler.IsCatchBlockExist) { throw; }

                // Search for the best handler in the TryCatchFinally block. If no suitable handler is found, rethrow
                ExceptionHandler exHandler;
                frame.InstructionIndex += _tryHandler.GotoHandler(frame, exception, out exHandler);
                if (exHandler == null) { throw; }
#if !CORECLR // Thread.Abort and ThreadAbortException are not in CoreCLR.
                // stay in the current catch so that ThreadAbortException is not rethrown by CLR:
                var abort = exception as ThreadAbortException;
                if (abort != null)
                {
                    Interpreter.AnyAbortException = abort;
                    frame.CurrentAbortHandler = exHandler;
                }
#endif
                bool rethrow = false;
                try
                {
                    // run the catch block
                    int index = frame.InstructionIndex;
                    while (index >= exHandler.HandlerStartIndex && index < exHandler.HandlerEndIndex)
                    {
                        index += instructions[index].Run(frame);
                        frame.InstructionIndex = index;
                    }

                    // we finish the catch block and is about to jump out of the try/catch blocks
                    if (index == _tryHandler.GotoEndTargetIndex)
                    {
                        // run the 'Goto' that jumps out of the try/catch/finally blocks
                        Debug.Assert(instructions[index] is GotoInstruction, "should be the 'Goto' instruction that jumps out the try/catch/finally");
                        frame.InstructionIndex += instructions[index].Run(frame);
                    }
                }
                catch (RethrowException)
                {
                    // a rethrow instruction in a catch block gets to run
                    rethrow = true;
                }

                if (rethrow) { throw; }
            }
            finally
            {
                if (_tryHandler.IsFinallyBlockExist)
                {
                    // We get to the finally block in two paths:
                    //  1. Jump from the try/catch blocks. This includes two sub-routes:
                    //        a. 'Goto' instruction in the middle of try/catch block
                    //        b. try/catch block runs to its end. Then the 'Goto(end)' will be trigger to jump out of the try/catch block
                    //  2. Exception thrown from the try/catch blocks
                    // In the first path, the continuation mechanism works and frame.InstructionIndex will be updated to point to the first instruction of the finally block
                    // In the second path, the continuation mechanism is not involved and frame.InstructionIndex is not updated
#if DEBUG
                    bool isFromJump = frame.IsJumpHappened();
                    Debug.Assert(!isFromJump || (isFromJump && _tryHandler.FinallyStartIndex == frame.InstructionIndex), "we should already jump to the first instruction of the finally");
#endif
                    // run the finally block
                    // we cannot jump out of the finally block, and we cannot have an immediate rethrow in it
//.........这里部分代码省略.........
开发者ID:40a,项目名称:PowerShell,代码行数:101,代码来源:ControlFlowInstructions.cs


注:本文中的System.Management.Automation.Interpreter.InterpretedFrame.SaveTraceToException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。