Complete the code to catch errors from the promise.
fetchData().then(data => console.log(data)).[1](error => console.error(error));The catch method is used to handle errors from promises.
Complete the code to handle errors using async/await with try/catch.
async function load() {
try {
const data = await fetchData();
console.log(data);
} catch ([1]) {
console.error(error);
}
}The catch block receives the error object, commonly named error.
Fix the error in the promise chain to properly catch errors.
fetchData() .then(data => console.log(data)) .[1](error => console.log('Error:', error));
The catch method must be used to catch errors in a promise chain.
Fill both blanks to handle errors and always run cleanup code.
fetchData() .then(data => console.log(data)) .[1](error => console.error(error)) .[2](() => console.log('Cleanup done'));
Use catch to handle errors and finally to run code regardless of success or failure.
Fill all three blanks to create a promise chain that logs data, catches errors, and always logs completion.
fetchData() .[1](data => console.log(data)) .[2](error => console.error('Error:', error)) .[3](() => console.log('Done'));
The promise chain uses then to handle success, catch for errors, and finally for code that runs always.
