Mr. Tono’s order burns and nobody catches it: when does the unhandledrejection bell ring, and what happens when Bagas comes late with a catch? Real events…
Why it matters
An escaped promise error does not stop the page, so it is easy to miss: in production it only shows in the user’s console. Knowing when the browser reports (and when it withdraws a report) tells you where to put the .catch, the await, and the error-log listener.
The key idea
Reported once the microtasks are done, withdrawn when handled later
Common mistakes
A try/catch round an async call but no await: the error still escapes Without await the call hands back a promise at once, and the try is over when that promise rejects. Write await pesan() inside the try, or pesan().catch(…).
Thinking unhandledrejection fires the moment it rejects, while it waits The browser checks once the microtasks are done, then reports in a task. A handler attached before that prevents the report; one that comes after it triggers rejectionhandled.
Promise errors escape without a trace in production, nothing visible in the console Add window.addEventListener('unhandledrejection', …) and send event.reason to your error log (in Node: process.on('unhandledRejection', …)). Listen for rejectionhandled too, to withdraw the entry.
Try it in this playground
Watch the report wait The bell only rings after 'pesanan dicatat'.
A handler one microtask later is still in time Open One microtask later.
Caught late: rejectionhandled Open Caught late and run to 300 ms.
try without await catches nothing Open try without await.