Window: rejectionhandled event
当 Promise
被 rejected
且有 rejection
处理器时会在全局触发 rejectionhandled
事件 (通常是发生在 window 下,但是也可能发生在 Worker 中)。应用于调试一般应用回退。当 Promise
被 rejected
且没有 rejection
处理器处理时会触发 unhandledrejection
事件。这两个事件协同工作。
是否冒泡 | No |
---|---|
是否可取消 | No |
接口 | PromiseRejectionEvent |
事件处理器属性 | onrejectionhandled |
示例
你可以使用rejectionhandled 事件在控制台打印出被 rejected 的 Promise,以及被 rejected 的原因:
js
window.addEventListener(
"rejectionhandled",
(event) => {
console.log("Promise rejected; reason: " + event.reason);
},
false,
);
规范
Specification |
---|
HTML # unhandled-promise-rejections |
HTML # handler-window-onrejectionhandled |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | server | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
rejectionhandled event |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.