Lua中如何捕获异常?我正在使用LuaJava
我正在使用luajava。 当lua执行错误时,我无法捕获异常,然后jdk崩溃了。 那么我怎样才能捕获lua中的异常呢?我只是捕获这样的错误(java代码):
LuaState ls = LuaStateFactory.newLuaState();
ls.openLibs();
String luaPath = "test.lua";
int isCompile = ls.LdoFile(luaPath);
if(isCompile==0){
log.info(luaPath+" compile success!");
}else{
log.info(luaPath+" script does not exist or compile failed!");
}
当lua有内部错误时,我无法捕获。 那么如何捕获lua中的异常呢?
当lua执行错误时,JVM显示错误,而不是异常。 如何捕获 Java 中的错误?
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.info(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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有点黑客,但我能想到解决这个问题的唯一方法是做这样的事情:
抱歉,如果这不是你所要求的,但是 LuaJava 文档毫无价值,所以我不知道是什么具体的运行时异常是。
Bit of a hack, but the only way I can think of to fix this is to do something like this:
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 不会抛出任何异常。您可以尝试的一种方法是生成一个新线程来尝试运行 lua 脚本。
LuaState.LdoFile doesn't throw any exceptions. One approach you might try is to spawn a new thread to attempt running the lua script.