Two new global events, unhandledrejection and
rejectionhandled, can be used to keep track of
rejections, including whether those rejections are handled after the fact.
The unhandledrejection event is the promise-equivalent of the
event, which is fired for uncaught exceptions. Because a rejected promise
could be handled after the fact, by attaching catch(onRejected)
or then(onFulfilled, onRejected) to it, the additional
rejectionhandled event is needed to indicate that a promise which
was previously rejected should no longer be considered unhandled.
These two events can be used, for example, to keep track of unhandled
rejections as part of an error-reporting framework.
The buttons below can be used to create new rejected promises that are either
eventually handled, or just left unhandled. The corresponding
unhandledrejection events (and rejectionhandled if
the promise is eventually handled) are logged.
This sample also shows how a web app might keep a running tally of all
unhandled rejections in a Map object. This could come in handy
when working with a centralized error reporting infrastructure, where you
want to log all rejected promises that have gone unhandled up to that point.