Recall & Review
beginner
What does the
catch method do in a Promise?The
catch method handles errors or rejections that happen in the Promise chain. It lets you respond to problems without crashing your program.Click to reveal answer
beginner
How do you attach a
catch to an async function call that returns a Promise?You call the async function and then add
.catch(error => { /* handle error */ }) after it to catch any errors that happen inside the async function.Click to reveal answer
beginner
Why is it important to use
catch with Promises?Without
catch, errors inside Promises can go unnoticed and cause your app to behave unexpectedly or crash. catch helps keep your app stable by handling those errors.Click to reveal answer
intermediate
What happens if you forget to add
catch to a Promise?If you forget
catch, unhandled Promise rejections may occur, which can cause warnings or crashes depending on your Node.js version and settings.Click to reveal answer
beginner
Show a simple example of using
catch with an async function.Example:<br><pre>async function fetchData() {
throw new Error('Oops!');
}
fetchData()
.catch(error => console.log('Error caught:', error.message));</pre>Click to reveal answer
What does
promise.catch() do?✗ Incorrect
catch is used to handle errors or rejections from a Promise.Which of these is the correct way to catch errors from an async function
getData()?✗ Incorrect
You attach
.catch() directly to the Promise returned by the async function.What happens if you don't use
catch on a Promise that rejects?✗ Incorrect
Unhandled Promise rejections can cause warnings or crashes in Node.js.
Can
catch be used to handle errors from multiple Promises chained together?✗ Incorrect
A single
catch at the end of a Promise chain catches errors from any Promise in the chain.Which Node.js version introduced warnings for unhandled Promise rejections by default?
✗ Incorrect
Node.js 10 started showing warnings for unhandled Promise rejections by default.
Explain how to use
catch to handle errors from an async function returning a Promise.Think about how you would stop your app from crashing when an async call fails.
You got /4 concepts.
Why is it important to always add a
catch when working with Promises in Node.js?Consider what happens if errors are ignored in your code.
You got /4 concepts.