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;
}
}- ✓Correct answer: The promise is returned without
await, so it rejects after leaving thetry; usereturn await fetchUser() - 2
try/catchnever works in async functions - 3
catchneeds afinallyblock to work
Explanation
Inside try, return await waits for settlement, so the rejection is thrown inside the block. Outside try/catch, plain return promise is fine.