开发者

How To Catch Exception In Lua? I Am Using LuaJava

开发者 https://www.devze.com 2023-03-13 11:17 出处:网络
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):

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消