function main()
--抛出异常
throw({retcode = "E001",retmsg = "出错了!!!",})
end
--捕获异常
local ok, result = pcall(main)
if not ok then
log(m_uuid,"throw err:"..tostring(result) )
end
ERR = {
SUCCESS = { retcode = "0000", retmsg = "success" },
SYSTEM_ERROR = { retcode = "E001", retmsg = "system error" },
MAC_ERROR = { retcode = "E002", retmsg = "mac error" },
}
function throw(err, ret)
local SYSTEM_ERROR = ERR.SYSTEM_ERROR
if type(err) ~= "table" then
error { retcode = SYSTEM_ERROR.retcode, retmsg = string.format("throw : err is %s", tostring(err)), }
end
if ret and type(ret) ~= "table" then
error { retcode = err.retcode, retmsg = tostring(ret) }
end
ret = ret or err or SYSTEM_ERROR
ret.retcode = (err or SYSTEM_ERROR).retcode
ret.retmsg = ret.retmsg or err.retmsg
error(ret)
end
lua pcall error
最新推荐文章于 2022-06-14 11:04:13 发布