Bird
0
0

What is wrong with this custom error class?

medium📝 Debug Q7 of 15
Node.js - Error Handling Patterns
What is wrong with this custom error class?
class MyError extends Error { constructor() { super(); this.name = 'MyError'; } }
When throwing new MyError('fail'), what happens?
AThe error name is not set
BThe message 'fail' is ignored because constructor has no parameters
CThe error message is set correctly
DThe error throws a syntax error
Step-by-Step Solution
Solution:
  1. Step 1: Check constructor parameters

    The constructor has no parameters, so the passed message 'fail' is not received or passed to super.
  2. Step 2: Effect on error message

    Since super() is called without arguments, the error message is empty or undefined, ignoring 'fail'.
  3. Final Answer:

    The message 'fail' is ignored because constructor has no parameters -> Option B
  4. Quick Check:

    Constructor must accept and pass message to super [OK]
Quick Trick: Constructor must accept message and pass to super(message) [OK]
Common Mistakes:
  • Not defining constructor parameters
  • Calling super() without message
  • Expecting message to be set automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes