Skip to content
engineering workbench.by StudyPort Academy
All errors
async · DEBUG LIBRARY

Unhandled promise rejection

Locate the failed assumption, reproduce it, then repair the cause.

What actually caused it

A rejected and no rejection handler owned that failure when the runtime checked it. Browsers often display “Uncaught (in promise)” followed by the rejection reason; other runtimes use different wording.

An returns a . Calling it without awaiting, returning, or attaching a rejection handler can leave an error unhandled. Starting an inner promise inside then without returning it creates another common gap in a chain.

A try around a call does not catch a later rejected unless that promise is awaited within the try. A try with neither catch nor finally is instead a syntax error; it is not a valid rejection-handling pattern.

Minimal reproduction

A rejected async call with no owner

async function loadProfile() {
  throw new Error("Profile unavailable");
}
loadProfile();

A try that does not await

async function loadProfile() { throw new Error("Offline"); }
try {
  loadProfile();
} catch (error) {
  console.error(error.message);
}

The rejection happens through the returned , outside this catch.

The fix

Assign error ownership at a useful boundary. Await the operation inside a try/catch, attach catch to the returned , or return the promise to a caller that will handle it. Not every await needs its own catch when rejection deliberately propagates to an owner.

Report or recover from the failure intentionally. An empty catch hides the bug. If a catch rethrows, the resulting rejected still needs a caller responsible for handling it. A global unhandledrejection listener is useful for diagnostics, not a substitute for normal control flow.

Await inside the handling boundary

async function loadProfile() { throw new Error("Offline"); }
async function showProfile() {
  try {
    await loadProfile();
  } catch (error) {
    console.error(`Could not load profile: ${error.message}`);
  }
}
showProfile();