Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk2 min

Why `window.onerror` Misses Unhandled Promise Rejections

Browser script errors and unhandled Promise rejections use separate events. Capture escaped rejections with a window.unhandledrejection listener.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

window.onerror does not capture unhandled Promise rejections. It handles script errors; a rejection with no handler is reported through the separate unhandledrejection event. Add a listener for that event to log or report escaped rejections.

Why doesn’t window.onerror catch a rejected Promise?

Browsers use separate reporting paths for script errors and Promise rejections. The Window error event reports synchronous script errors. When a Promise is rejected without a rejection handler, the browser fires unhandledrejection on the relevant global scope, usually window. MDN describes the distinction in its Window: error event documentation.

As an Amazon Associate I earn from qualifying purchases.

How do you capture unhandled rejections?

Register a listener on the global object:

window.addEventListener("unhandledrejection", (event) => {
  console.error("Unhandled promise rejection:", event.reason);
});

The event is a PromiseRejectionEvent. Its reason property contains the rejection value, and promise identifies the rejected Promise. A rejection reason can be any value, not necessarily an Error, so avoid assuming it has properties such as message or stack.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

You can also assign window.onunhandledrejection. Use addEventListener when listeners need to coexist: assigning the property replaces any existing property handler.

What does the global listener cover—and what does it not?

The event reports Promise rejections that have no rejection handler when the browser reports them. It is a diagnostic safety net, not a guarantee that every failure will reach your code. In particular, cross-origin script rejections may not dispatch unhandledrejection, because exposing rejection details could reveal data across origins. See MDN’s Window: unhandledrejection event documentation.

Handle expected failures near the operation that can fail. For example, use try/catch around an await when you can recover, or attach .catch() to a Promise chain. The global listener can then help reveal rejections that escaped those local handling paths.

Should you call preventDefault()?

unhandledrejection is cancelable. Calling event.preventDefault() suppresses the browser’s default handling, such as reporting the rejection in the console. Do so only if your application deliberately takes responsibility for handling or reporting the failure; otherwise, leave the default behavior intact while logging or observing the event.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What if the rejection gets handled later?

A Promise can be reported as unhandled and then receive a rejection handler afterward. The global scope may then fire rejectionhandled. Instrumentation can use this signal to update an earlier report rather than treating the first event as proof that the rejection remained unhandled indefinitely. MDN documents this event in its Window: rejectionhandled event reference.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Browser event names differ from Node.js

In browser code, listen for unhandledrejection on the global scope. Node.js uses a differently capitalized process event, unhandledRejection; its process-listener examples are not browser Window event handlers.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.