12 / 17

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

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

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

Scenario Questions

0-2 years experience
  1. 1

    You need to fetch user data with fetch and async/await. How would you catch a network error and return a default object?

  2. 2

    If 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. 1

    We 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. 2

    During 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. 1

    Our 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. 2

    When 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. 1

    We 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. 2

    How 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?