Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q14 of 15
Node.js - Error Handling Patterns
Identify the error in this code snippet:
try {
  console.log('Start');
  throw 'Error happened';
} catch e {
  console.log('Caught:', e);
}
AConsole.log syntax is wrong
BThrow cannot use string errors
CMissing parentheses around catch parameter
DTry block must not contain throw
Step-by-Step Solution
Solution:
  1. Step 1: Check catch syntax

    The catch block must have parentheses around the error variable, like catch (e).
  2. Step 2: Verify other parts

    Throwing a string is allowed, console.log syntax is correct, and throw is valid inside try.
  3. Final Answer:

    Missing parentheses around catch parameter -> Option C
  4. Quick Check:

    Catch needs parentheses = A [OK]
Quick Trick: Catch always needs parentheses around error variable [OK]
Common Mistakes:
  • Omitting parentheses in catch
  • Thinking throw can't use strings
  • Misreading console.log syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes