pcall

来源:互联网 发布:中国知网的数据库 编辑:程序博客网 时间:2024/05/17 03:17

If you need to handle errors in Lua, you must use the pcall (protected call) function to encapsulate your code.

The pcall function calls its first argument in protected mode, so that it catches any errors while the function is running. If there are no errors, pcall returns true, plus any values returned by the call. Otherwise, it returns false, plus the error message.

local status, err = pcall(function()    error({code=121})end)print(err.code) --> 121
0 0
原创粉丝点击