12 / 17

How do you handle errors when using `async/await`?

Difficulty: 5/10
try/catch, promise rejection, error propagation

You can use a try/catch block around an await statement to catch errors that occur within the awaited Promise.

javascript

Scenario Questions

0-2 years experience

  1. 1You need to fetch user data with fetch and async/await. How would you catch a network error and return a default object?
  2. 2If an async function throws inside a try block, what does the caller receive if you don't use try/catch?

2-5 years experience

  1. 1We have a function that calls two async services sequentially. It sometimes fails on the second call, leaving the first call's side effects persisted. How would you restructure error handling to ensure consistency?
  2. 2During debugging you notice an unhandled promise rejection warning even though you wrapped the await in try/catch. What could cause that?

5-8 years experience

  1. 1Our microservice layer uses async/await throughout and we need a centralized way to log and transform errors before they bubble up. How would you design such a mechanism without losing stack traces?
  2. 2When scaling to thousands of concurrent requests, what impact does using try/catch in every async handler have on performance, and how would you mitigate any overhead?

8+ years experience

  1. 1We are migrating a legacy callback‑heavy codebase to async/await across multiple teams. What strategy would you use to enforce consistent error handling patterns and avoid silent failures?
  2. 2How would you integrate async/await error handling with a distributed tracing system to ensure errors are captured across service boundaries?

Follow-up Questions

  • Can you walk me through how the error propagates back to the caller in your example?
  • What are the trade‑offs between handling errors locally with try/catch versus a global error handler?
  • How would you test that your error handling behaves correctly under network failures?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.