该rejectionhandled事件应在unhandledrejection事件处理程序将拒绝处理程序 ( catch()) 附加到 Promise 后触发,但它没有
在 node.js 中,我们有相同的unhandledRejection和rejectionHandled可以正常工作的事件
我错过了什么?
onunhandledrejection = function(ev){ // event property triggered as expected (promise ha a missing rejection handler)
console.log( 'promise has no rejection handler!' );
ev.promise // the promise that has no rejection handler
.catch(err => console.log(err)) // attaching the rejection handler to the promise (THIS SHOULD TRIGGER THE rejectionhandler event)
}
onrejectionhandled = function(ev){ // NOT triggered
console.log( 'rejection handled!' );
}
addEventListener('rejectionhandled', function(ev){ // NOT triggered
console.log( 'rejection handled!' );
})
Promise.reject("I'm rejected!"); // rejected promise without rejection handler