redo the error handling due to the changes in DebugStackState made by James

This commit is contained in:
Shu Lei
2007-10-25 00:11:23 +00:00
parent 72c01f76c0
commit abf34c460d
3 changed files with 28 additions and 14 deletions

View File

@@ -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();
}

View File

@@ -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());
}
}

View File

@@ -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]);
}
try {
getDebugState().doCall(c, vargs);
} catch (VMException e) {
System.err.println("VMException: " + e.getMessage());
}
getDebugState().stop();
}