PromiseRejectionEvent
Note: This feature is available inWeb Workers.
ThePromiseRejectionEvent interface represents events which are sent to the global script context when JavaScriptPromises are rejected. These events are particularly useful for telemetry and debugging purposes.
For details, seePromise rejection events.
In this article
Constructor
PromiseRejectionEvent()Creates a
PromiseRejectionEventevent, given the type of event (unhandledrejectionorrejectionhandled) and other details.
Instance properties
Also inherits properties from its parentEvent.
PromiseRejectionEvent.promiseRead onlyThe JavaScript
Promisethat was rejected.PromiseRejectionEvent.reasonRead onlyA value or
Objectindicating why the promise was rejected, as passed toPromise.reject().
Instance methods
This interface has no unique methods; inherits methods from its parentEvent.
Events
rejectionhandledFired when a JavaScript
Promiseis rejected, and after the rejection is handled by the promise's rejection handling code.unhandledrejectionFired when a JavaScript
Promiseis rejected but there is no rejection handler to deal with the rejection.
Examples
This simple example catches unhandled promise rejections and logs them for debugging purposes.
window.onunhandledrejection = (e) => { console.log(e.reason);};Specifications
| Specification |
|---|
| HTML> # promiserejectionevent> |