PromiseRejectionEvent
PromiseRejectionEvent represents a Promise rejection that wasn't handled. It is the event object of the unhandledrejection event on application, carrying the rejection reason and the rejected Promise.
Inheritance: Event → PromiseRejectionEvent
Constructor
Creates a rejection event object. The runtime creates it itself when firing unhandledrejection; app code generally doesn't need it.
Instance properties
Also inherits properties from Event. For the unhandledrejection event fired by the runtime, cancelable is true.
| Property | Description |
|---|---|
reason read-only | The rejection reason |
promise read-only | The Promise that was rejected |
Examples
js
application.addEventListener('unhandledrejection', (e) => {
console.log(e instanceof PromiseRejectionEvent, String(e.reason));
e.preventDefault();
});
Promise.reject(new Error('Nobody caught this'));Result: Prints true Error: Nobody caught this.
Comparison with the browser
| Browser | Nacre |
|---|---|
rejectionhandled event | None |