AceDevHub
Intermediate JavaScript Interview QuestionsIntermediateScenario

JavaScript · Question 50

How should errors be handled in Promise chains and async/await code?

Direct answer

Handle an error at the layer that can add context or recover, allow unrecoverable errors to propagate, and use finally for cleanup that must run on both success and failure.

An async function converts an uncaught thrown exception into a rejected Promise. That means try/catch around an await and .catch() on a Promise chain are two ways of participating in the same rejection model.

  • Catch when you can recover, translate the error, add useful context, or produce a deliberate fallback.
  • Do not write empty catches that silently convert failures into undefined behavior.
  • If you catch only to log, consider whether you also need to rethrow so upstream code still sees failure.
  • finally is useful for releasing UI/loading state or other cleanup; it should not normally replace the original result unless it throws or returns a rejected Promise.

With concurrent operations, the combinator matters: Promise.all() exposes the first observed rejection for the aggregate, whereas Promise.allSettled() lets you inspect every outcome.