加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

错误处理 – Lua错误处理

发布时间:2020-12-14 21:43:23 所属栏目:大数据 来源:网络整理
导读:我是lua的新手. 我试过用 http://keplerproject.github.io/luafilesystem/examples.html 并且它在无法访问的目录上引发错误. 这似乎是由luaL_error https://github.com/keplerproject/luafilesystem/blob/master/src/lfs.c#L563引起的 我怎么能抓到这个错误
我是lua的新手.

我试过用
http://keplerproject.github.io/luafilesystem/examples.html
并且它在无法访问的目录上引发错误.

这似乎是由luaL_error https://github.com/keplerproject/luafilesystem/blob/master/src/lfs.c#L563引起的

我怎么能抓到这个错误?
http://www.tutorialspoint.com/lua/lua_error_handling.htm
建议pcall,但这不会阻止脚本死亡:

pcall(lfs.dir('/etc/passwd')) #this fails to handle the not a directory error

解决方法

pcall(lfs.dir(‘/ etc / passwd’))失败,因为错误是在pcall之外触发的(当计算pcall的参数时).你需要使用

local ok,res = pcall(lfs.dir,'/etc/passwd')

请注意,传递给lfs.dir的参数是给pcall的,而不是lfs.dir.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读