my.onunhandledrejection(function listener)
基础库 或更高版本; 且 支付宝客户端 10.1.75 或更高版本; 若版本较低,建议采取 兼容处理 。
主体: 企业支付宝小程序 、 个人支付宝小程序
相关文档: app.onunhandledrejection
监听未处理的 promise 拒绝事件。
function listener
未处理的 promise 拒绝事件的监听函数
参数
object res
查看示例
属性 | 类型 | 描述 |
---|---|---|
reason | unknown | 拒绝原因,一般是一个 error 对象 |
promise | promise |
被拒绝的 promise 对象。注意:安卓上从基础库 2.9.7 开始支持此字段 |
my.onunhandledrejection(function listener)
page({
onload() {
my.onunhandledrejection(this.unhandledrejectionhandler);
},
unhandledrejectionhandler(res) {
console.log('onunhandledrejection reason', res.reason);
console.log('onunhandledrejection promise', res.promise);
}
})
-
tip如果 app.onunhandledrejection 事件,或 my.onunhandledrejection 的回调函数内继续触发
promise
的unhandledrejection
事件,则可能会导致循环触发unhandledrejection
事件,请注意规避。 -
tip所有的
unhandledrejection
都可以被这一监听捕获,但只有error
类型的才会在小程序后台触发报警。