JavaScript · Middle · Question 52 of 75

Why does this catch not handle the rejection?

async function load() {
  try {
    return fetchUser(); // returns a rejected promise
  } catch (e) {
    return null;
  }
}

Explanation

Inside try, return await waits for settlement, so the rejection is thrown inside the block. Outside try/catch, plain return promise is fine.

Further reading

Problem with a question

JavaScript · Middle · question 52

Test yourself

Take the JavaScript · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz