Browse Source

Change: Wrap runtime exception in VM

Akeit0 1 year ago
parent
commit
cd62c78441
2 changed files with 7 additions and 2 deletions
  1. 6 1
      src/Lua/Exceptions.cs
  2. 1 1
      src/Lua/Runtime/LuaVirtualMachine.cs

+ 6 - 1
src/Lua/Exceptions.cs

@@ -97,4 +97,9 @@ public class LuaAssertionException(Traceback traceback, string message) : LuaRun
     }
 }
 
-public class LuaModuleNotFoundException(string moduleName) : LuaException($"module '{moduleName}' not found");
+public class LuaModuleNotFoundException(string moduleName) : LuaException($"module '{moduleName}' not found");
+
+public class LuaRuntimeCSharpException(Traceback traceback, Exception exception) : LuaRuntimeException(traceback, exception.Message)
+{
+    public Exception Exception { get; } = exception;
+}

+ 1 - 1
src/Lua/Runtime/LuaVirtualMachine.cs

@@ -980,7 +980,7 @@ public static partial class LuaVirtualMachine
             {
                 if (e is not LuaRuntimeException)
                 {
-                    Console.WriteLine(GetTracebacks(ref context));
+                    e = new LuaRuntimeCSharpException(context.State.GetTraceback(), e);
                 }
 
                 context.PopOnTopCallStackFrames();