I am using luajava. When lua execute wrong,I cannot catch exception,and then jdk crashed. So how can I catch exception in lua?I just catch error like this(java code):
LuaState ls = LuaStateFactory.newLuaState();
ls.openLibs();
String luaPath = "test.lua";
int isCompile = ls.LdoFile(luaPath);
if(isCompile==0){
log.inf开发者_JAVA百科o(luaPath+" compile success!");
}else{
log.info(luaPath+" script does not exist or compile failed!");
}
When lua has internal error,I cannot catch. So how can I catch exception in lua?
When lua executes error, JVM shows an error, not an exception. How can I catch the error in Java?
Bit of a hack, but the only way I can think of to fix this is to do something like this:
LuaState ls = LuaStateFactory.newLuaState();
ls.openLibs();
String luaPath = "test.lua";
int isCompile;
try {
isCompile = ls.LdoFile(luaPath);
} catch (Exception ex {
ex.printStackTrace(System.err);
isCompile = 1;
}
if(isCompile==0){
log.info(luaPath+" compile success!");
}else{
log.info(luaPath+" script does not exist or compile failed!");
}
Sorry if this isn't what your asking, but the LuaJava doc is worthless, so I have no idea what the specific runtime exception is.
LuaState.LdoFile doesn't throw any exceptions. One approach you might try is to spawn a new thread to attempt running the lua script.
精彩评论