← Quiz: Async JavaScript: all 10 questions
Quiz: Async JavaScript · Question 9 of 10
How do you handle errors when using await?
How do you handle errors when using await?
- A.You cannot; await hides errors
- B.Wrap the awaited calls in try { … } catch (err) { … }
- C.Add .finally() to the function name
- D.Use setTimeout
Answer & explanation
Correct answer: Wrap the awaited calls in try { … } catch (err) { … }
A rejected promise makes await throw, so try/catch works just like with normal code.
Can you get the rest right without peeking?
Take the timed Quiz: Async JavaScript quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →