Recall & Review
beginner
What is the purpose of
.catch() in a JavaScript Promise?.catch() is used to handle errors or rejections that happen in a Promise chain. It catches any error thrown or rejection from the Promise and lets you respond to it.Click to reveal answer
beginner
How does
try...catch work with async/await for error handling?When using
async/await, you can wrap the await call inside a try block. If the Promise rejects, the error is caught in the catch block, allowing you to handle it cleanly.Click to reveal answer
beginner
What happens if you don't handle a rejected Promise?
If a Promise rejects and you don't handle it with
.catch() or try...catch, it causes an unhandled promise rejection. This can crash your program or cause unexpected behavior.Click to reveal answer
intermediate
Can you chain multiple
.catch() handlers on a Promise?No, only the first
.catch() in the chain will catch the error. After an error is caught, the chain continues normally unless you throw another error.Click to reveal answer
intermediate
How can you handle errors in multiple Promises running in parallel?
You can use
Promise.allSettled() to wait for all Promises to finish, then check which ones failed. Or use Promise.all() with a .catch() to handle if any reject.Click to reveal answer
Which method is used to catch errors in a Promise chain?
✗ Incorrect
.catch() is specifically designed to handle errors or rejections in Promises.What happens if a Promise rejects but no
.catch() is provided?✗ Incorrect
Without a
.catch(), rejected Promises cause unhandled promise rejections, which can crash the program.How do you handle errors when using
async/await?✗ Incorrect
Errors from
await can be caught using try...catch blocks.Which Promise method lets you wait for all Promises to finish regardless of success or failure?
✗ Incorrect
Promise.allSettled() waits for all Promises to settle, whether fulfilled or rejected.If you want to handle errors only once in a Promise chain, where should you place
.catch()?✗ Incorrect
Placing
.catch() at the end catches any error from the entire chain.Explain how to handle errors in a Promise chain using
.catch().Think about how you catch mistakes in a sequence of steps.
You got /4 concepts.
Describe how
try...catch works with async/await for error handling.Imagine waiting for a task and catching problems as if it was normal code.
You got /4 concepts.