diff --git a/src/main/java/lua/debug/DebugStackState.java b/src/main/java/lua/debug/DebugStackState.java index c3595fd5..6e325bd0 100644 --- a/src/main/java/lua/debug/DebugStackState.java +++ b/src/main/java/lua/debug/DebugStackState.java @@ -65,7 +65,8 @@ public class DebugStackState extends StackState implements DebugRequestListener protected boolean suspended = false; protected int lastline = -1; protected String lastSource; - protected DebugSupport debugSupport = null; + protected DebugSupport debugSupport; + protected VMException lastException; public DebugStackState() {} @@ -112,26 +113,21 @@ public class DebugStackState extends StackState implements DebugRequestListener error(message, 1); } - private void printLuaTrace() { - System.out.println( "Lua location: "+getFileLine(cc) ); - for ( int cindex=cc-1; cindex>=0; cindex-- ) - System.out.println( "\tin "+getFileLine( cindex ) ); - } - // intercept exceptions and fill in line numbers public void exec() { try { super.exec(); - } catch (AbortException e) { + } catch ( AbortException e ) { // ignored. Client aborts the debugging session. - } catch ( RuntimeException t ) { - // let other exceptions be processed + } catch ( VMException e ) { + // let VM exceptions be processed // the same as the base class to minimize differences // between the debug and non-debug behavior - - debugSupport.notifyDebugEvent(new DebugEventError(t.getMessage())); + throw e; + } catch ( Exception e ) { + lastException = new VMException(e); + debugSupport.notifyDebugEvent(new DebugEventError(e.getMessage())); suspend(); - throw t; } } @@ -209,6 +205,10 @@ public class DebugStackState extends StackState implements DebugRequestListener this.wait(); if(DebugUtils.IS_DEBUG) DebugUtils.println("resuming execution..."); + + if (lastException != null) { + throw lastException; + } } catch ( InterruptedException ie ) { ie.printStackTrace(); } diff --git a/src/main/java/lua/debug/VMException.java b/src/main/java/lua/debug/VMException.java new file mode 100644 index 00000000..6d07503e --- /dev/null +++ b/src/main/java/lua/debug/VMException.java @@ -0,0 +1,9 @@ +package lua.debug; + +public class VMException extends RuntimeException { + private static final long serialVersionUID = 7876955153693775429L; + + public VMException(Exception e) { + super(e.getMessage()); + } +} diff --git a/src/main/java/lua/debug/j2se/StandardLuaJVM.java b/src/main/java/lua/debug/j2se/StandardLuaJVM.java index 9e5cea61..7587da2e 100644 --- a/src/main/java/lua/debug/j2se/StandardLuaJVM.java +++ b/src/main/java/lua/debug/j2se/StandardLuaJVM.java @@ -33,6 +33,7 @@ import lua.addon.luajava.LuaJava; import lua.debug.DebugStackState; import lua.debug.DebugSupport; import lua.debug.DebugUtils; +import lua.debug.VMException; import lua.io.Closure; import lua.io.LoadState; import lua.io.Proto; @@ -220,7 +221,11 @@ public class StandardLuaJVM { for (int i = 0; i < numOfScriptArgs; i++) { vargs[i] = new LString(args[i]); } - getDebugState().doCall(c, vargs); + try { + getDebugState().doCall(c, vargs); + } catch (VMException e) { + System.err.println("VMException: " + e.getMessage()); + } getDebugState().stop(); }