PromiseRejectionEvent.promise
PromiseRejectionEvent
事件对象的promise
属性是只读的,表明Promise被reject的原因。您可以通过检查PromiseRejectionEvent.reason
(en-US)来了解Promise为什么被reject。
Syntax
promise = PromiseRejectionEvent.promise
Value
一个被reject的,并且错误未被处理的Promise
Examples
下面的例子监听了未被处理的promise,如果reason
(en-US) 是一个对象,并且其code
属性包含了一段文本“Module not read.”,一个空闲的回调函数被声明,当任务执行错误时会进行重试
event.preventDefault()
用来表明该promise已被处理
window.onunhandledrejection = function(event) {
if (event.reason.code && event.reason.code == "Module not ready") {
window.requestIdleCallback(function(deadline) {
loadModule(event.reason.moduleName)
.then(performStartup);
});
event.preventDefault();
}
}
Specifications
Specification | Status | Comment |
---|---|---|
HTML Living Standard PromiseRejectionEvent.promise |
Living Standard | Initial definition. |
浏览器兼容性
BCD tables only load in the browser