Async & Promisesmedium

Unhandled promise rejections: causes and fixes

Explain what unhandled promise rejections are, why they happen, and how to systematically prevent them in app code.

Asked at Meta, Amazon, Google

#promises#errors#debugging#best practices

Answer

Interview explanation:

  • An unhandled rejection means a promise rejected without a rejection handler.
  • In modern runtimes this is noisy and can crash processes (Node settings dependent).

Common causes:

  1. Fire-and-forget promise without .catch.
  2. Missing await in try/catch (error escapes scope).
  3. Missing return in .then chain.

Examples: void riskyAsync().catch(reportError) // explicit fire-and-forget handling

async function handler() { try { await riskyAsync() } catch (err) { reportError(err) } }

Prevention checklist:

  • Always return/await promises from functions.
  • Add a terminal .catch on top-level chains.
  • Wrap UI event async handlers in try/catch.
  • Centralize logging for unexpected async failures.

Practise more Async & Promises questions →