content
content copied to clipboard
Clarify when the rejectionhandled event does and does not fire
Fixes https://github.com/mdn/content/issues/22177. @bergus it would great to have your review on this, if you can make time — since it’s based on your wording from https://stackoverflow.com/a/57261820/441757
Preview URLs
(this comment was updated 2022-11-25 08:37:34.917907)
I'd recommend to rather change the part "whenever a JavaScript Promise is rejected but after the promise rejection has been handled". I'd write
The **`rejectionhandled`** event is sent to the script's global scope (usually {{domxref("window")}} but also {{domxref("Worker")}}) whenever a rejected JavaScript {{jsxref("Promise")}} is handled late, after its rejections had caused an {{domxref("Window.unhandledrejection_event", "unhandledrejection")}} event, by subsequently attaching a handler.
This can be used in debugging and for general application resiliency, in tandem with the `unhandledrejection` event, which is sent when a promise is rejected but there is no handler for the rejection at the time.
@bergus Thanks much — made it so
@Josh-Cena It's usually not the unhandledrejection listener that would attach this handler, but some other code that still has a reference to the promise.
Thanks, all. I will merge this shortly 👍🏻