函数:pcall 保护模式调用

函数名称:保护模式调用

函数功能:保护执行 function 函数, function 内部发生的错误不会影响脚本运行

函数方法

bool,msg = pcall(fun,action,...)

参数 类型 必填 说明
fun function 待调用参数
action - 待传入 fun 的参数,支持多个参数
返回值 类型 说明
bool boolean true - 无错误,false - 有错误
msg - 有错误时返回错误信息

函数示例

bool,msg=pcall(function(i) print(i) error('error..') end,33)
if bool then
    dialog("无错误")
else
    dialog(msg,5)
end
Copyright 北京帮你玩科技有限公司 2023 all right reserved,powered by Gitbook该文章修订时间: 2024-03-06 17:50:18

results matching ""

    No results matching ""