} // ctor protected override void OnExceptionUnwind(LuaTraceLineExceptionEventArgs e) { var luaFrames = new List <LuaStackFrame>(); var offsetForRecalc = 0; LuaExceptionData currentData = null; // get default exception data if (e.Exception.Data[LuaRuntimeException.ExceptionDataKey] is LuaExceptionData) { currentData = LuaExceptionData.GetData(e.Exception); offsetForRecalc = currentData.Count; luaFrames.AddRange(currentData); } else { currentData = LuaExceptionData.GetData(e.Exception, resolveStackTrace: false); } // re-trace the stack frame var trace = new StackTrace(e.Exception, true); for (var i = offsetForRecalc; i < trace.FrameCount - 1; i++) { luaFrames.Add(LuaExceptionData.GetStackFrame(trace.GetFrame(i))); } // add trace point luaFrames.Add(new LuaStackFrame(trace.GetFrame(trace.FrameCount - 1), new LuaTraceLineDebugInfo(e, engine.FindScript(e.SourceName)))); currentData.UpdateStackTrace(luaFrames.ToArray()); } // proc OnExceptionUnwind
protected override void OnExceptionUnwind(LuaTraceLineExceptionEventArgs e) { base.OnExceptionUnwind(e); var message = $"Exception caught: {e.Exception} On line: {e.SourceLine} in source {e.SourceName} and scope {e.ScopeName}. Last frame scope {_lastFrameScope.Peek()} trace line before exception unwind: {_lastTraceLine}."; throw new LuaDebuggerException(message, _lastFrameSourceName, _lastFrameScope.Peek(), _lastFrameLine, _lastTraceSourceName, _lastTraceScope, _lastTraceLine); }
protected override void OnExceptionUnwind(LuaTraceLineExceptionEventArgs args) { var errorBuilder = ScriptService.ErrorStringBuilder; if (!ScriptService.IsWritingError) { var e = args.Exception; do { Engine.Logger.Error(e.ToString()); errorBuilder.AppendLine(e.Message); e = e.InnerException; } while (e != null); } var line = $"Script '{_debugger.Script.GetFullName()}', Line {args.SourceLine}"; if (args.ScopeName != _debugger.Script.InstanceId) { string scopeType; if (args.Locals.ContainsKey(args.ScopeName)) { scopeType = "local"; } else if (_debugger.GetGlobals().ContainsKey(args.ScopeName)) { scopeType = "global"; } else { scopeType = "function"; } line += $" - {scopeType} {args.ScopeName}"; } errorBuilder.AppendLine(line); base.OnExceptionUnwind(args); }
protected override void OnExceptionUnwind(LuaTraceLineExceptionEventArgs e) { if (!lInException) { lInException = true; Console.WriteLine(); int iTop = Console.CursorTop; WriteText(ConsoleColor.DarkRed, "Exception: "); WriteText(ConsoleColor.Red, e.Exception.Message); Console.WriteLine(); WriteText(ConsoleColor.Gray, "press any key to continue"); Console.WriteLine(); Console.ReadKey(); int iClearTo = Console.CursorTop; Console.CursorLeft = 0; string sClear = new string(' ', Console.WindowWidth); for (int i = iTop; i <= iClearTo; i++) { Console.CursorTop = i; Console.WriteLine(sClear); } Console.CursorTop = iTop; } base.OnExceptionUnwind(e); }
public LuaTraceLineDebugInfo(LuaTraceLineExceptionEventArgs e, LuaScript script) { this.chunkName = e.SourceName; this.sourceFile = script?.ScriptBase ?? chunkName; this.line = e.SourceLine; } // ctor
public LuaTraceLineDebugInfo(LuaTraceLineExceptionEventArgs e, string sourceFile) { this.chunkName = e.SourceName; this.sourceFile = sourceFile; this.line = e.SourceLine; } // ctor