Bird
0
0

How do you correctly attach an error handler to a Promise called fetchData to catch any rejection?

easy📝 Syntax Q3 of 15
Node.js - Error Handling Patterns
How do you correctly attach an error handler to a Promise called fetchData to catch any rejection?
AfetchData.catch(error => console.error(error));
BfetchData.catch().then(error => console.error(error));
CfetchData.then().catch(error => console.error(error));
DfetchData().catch(error => console.error(error));
Step-by-Step Solution
Solution:
  1. Step 1: Identify if fetchData is a function

    Usually, fetchData is a function returning a Promise, so it must be called first.
  2. Step 2: Attach catch to the returned Promise

    Calling fetchData() returns a Promise, then catch handles errors.
  3. Final Answer:

    fetchData().catch(error => console.error(error)); -> Option D
  4. Quick Check:

    Is fetchData called before catch? Yes. [OK]
Quick Trick: Call function before catch to handle Promise errors [OK]
Common Mistakes:
  • Not calling fetchData as a function
  • Using catch without parentheses
  • Misplacing then before catch incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes