/// <summary> /// Constructor. /// </summary> /// <param name="interpreter">An IInterpreter instance.</param> /// <param name="parentWord">A word, that is executing this CATCH word.</param> /// <param name="nextWordIndex">An index of a word following this CATCH word..</param> public CatchWord(IInterpreter interpreter, IWord parentWord, int nextWordIndex) : base(interpreter) { Name = "CATCH"; IsControlWord = true; Action = () => { // Exception stack free. if ((interpreter.State.ExceptionStack.Count + 1) >= Interpreter.State.ExceptionStack.Items.Length) { throw new InterpreterException(-3, "Exception stack overflow."); } Interpreter.StackExpect(1); var exceptionFrame = new ExceptionFrame() { StackTop = Interpreter.State.Stack.Top, ObjectStackTop = Interpreter.State.ObjectStack.Top, ReturnStackTop = Interpreter.State.ReturnStack.Top, InputSourceStackTop = Interpreter.State.InputSourceStack.Top, ExecutingWord = _parentWord, NextWordIndex = _nextWordIndex }; Interpreter.State.ExceptionStack.Push(exceptionFrame); try { // Execute the word. var index = Interpreter.Execute(Interpreter.State.WordsList.Get(Interpreter.Pop())); // Remove the unused exception frame (nothing failed here). Interpreter.State.ExceptionStack.Pop(); // Return the OK status. Interpreter.Push(0); return(index); } catch (System.Exception) { // Clean up the mess, if needed. if (Interpreter.State.ExceptionStack.IsEmpty == false && Interpreter.State.ExceptionStack.Peek() == exceptionFrame) { Interpreter.State.ExceptionStack.Pop(); } // TODO: What to do with the exception? // Go to the word behind us. return(1); } }; _parentWord = parentWord; _nextWordIndex = nextWordIndex; }
public void Constructor_Preserves_Function_Names() { var stackTrace = new StackTrace(TestHelper.GetException()); var stackFrame = stackTrace.GetFrames().Last(); var frame = new ExceptionFrame(stackFrame); Assert.AreEqual(frame.Function, "GetException"); Assert.AreEqual(frame.Module, "SharpRaven.UnitTests.Utilities.TestHelper"); }
public void Constructor_NullFrameMethod_DoesNotThrow() { // on some platforms (e.g. on mono), StackFrame.GetMethod() may return null // e.g. for this stack frame: // at (wrapper dynamic-method) System.Object:lambda_method (System.Runtime.CompilerServices.Closure,object,object)) var stackFrame = new StackFrameWithNullMethod(); var frame = new ExceptionFrame(stackFrame); Assert.AreEqual("(unknown)", frame.Module); Assert.AreEqual("(unknown)", frame.Function); Assert.AreEqual("(unknown)", frame.Source); }
public void PreTest () { frame = SyncFrame.GUI.CountFrame (); object ApplicationException::meta }