如果需要在Lua中处理错误,必须使用函数pcall(protected call)来包装需要执行的代码。
pcall接收一个函数和要传递个后者的参数,并执行,执行结果:有错误、无错误;返回值true或者或false, errorinfo
if pcall(function_name, ….) then
-- no error
else
-- some error
end
简单示例
> =pcall(function(i) print(i)
如果需要在Lua中处理错误,必须使用函数pcall(protected call)来包装需要执行的代码。
pcall接收一个函数和要传递个后者的参数,并执行,执行结果:有错误、无错误;返回值true或者或false, errorinfo
if pcall(function_name, ….) then
-- no error
else
-- some error
end
简单示例
> =pcall(function(i) print(i)