0
0
Node.jsframework~10 mins

Promise catch for async errors in Node.js - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to catch errors from the promise.

Node.js
fetchData().then(data => console.log(data)).[1](error => console.error(error));
Drag options to blanks, or click blank then click option'
Aresolve
Bthen
Cfinally
Dcatch
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'then' instead of 'catch' to handle errors.
Using 'finally' to catch errors (it runs regardless of success or failure).
2fill in blank
medium

Complete the code to handle errors using async/await with try/catch.

Node.js
async function load() {
  try {
    const data = await fetchData();
    console.log(data);
  } catch ([1]) {
    console.error(error);
  }
}
Drag options to blanks, or click blank then click option'
Aerror
Bdata
Cresult
Dresponse
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that does not represent an error.
Leaving the catch parameter empty.
3fill in blank
hard

Fix the error in the promise chain to properly catch errors.

Node.js
fetchData()
  .then(data => console.log(data))
  .[1](error => console.log('Error:', error));
Drag options to blanks, or click blank then click option'
Athen
Bcatch
Cerror
Dfinally
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'then' to catch errors causes errors to be unhandled.
Using 'error' as a method name causes syntax errors.
4fill in blank
hard

Fill both blanks to handle errors and always run cleanup code.

Node.js
fetchData()
  .then(data => console.log(data))
  .[1](error => console.error(error))
  .[2](() => console.log('Cleanup done'));
Drag options to blanks, or click blank then click option'
Acatch
Bthen
Cfinally
Dresolve
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'then' instead of 'catch' for errors.
Not using 'finally' for cleanup.
5fill in blank
hard

Fill all three blanks to create a promise chain that logs data, catches errors, and always logs completion.

Node.js
fetchData()
  .[1](data => console.log(data))
  .[2](error => console.error('Error:', error))
  .[3](() => console.log('Done'));
Drag options to blanks, or click blank then click option'
Athen
Bcatch
Cfinally
Dresolve
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the order of then, catch, and finally.
Using 'resolve' which is not a method on promises.