Bird
0
0

Identify the error in this async function error handling code:

medium📝 Debug Q14 of 15
Node.js - Error Handling Patterns
Identify the error in this async function error handling code:
async function load() {
  try {
    const data = await fetchData();
  } catch {
    console.error(error);
  }
}
Aconsole.error cannot log variables
BAwait cannot be used inside try block
CfetchData() must be awaited outside try
DMissing error parameter in catch block
Step-by-Step Solution
Solution:
  1. Step 1: Check catch block syntax

    The catch block is missing the error parameter to receive the thrown error.
  2. Step 2: Understand console.error usage

    console.error(error) references a variable 'error' which is undefined without catch parameter.
  3. Final Answer:

    Missing error parameter in catch block -> Option D
  4. Quick Check:

    Catch needs error param = A [OK]
Quick Trick: Always name error in catch(e) to use it inside [OK]
Common Mistakes:
  • Omitting error parameter in catch
  • Misplacing await outside try
  • Misusing console.error syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes