Bird
0
0

Why should you extend the built-in Error class when creating a custom error in Node.js?

easy📝 Conceptual Q1 of 15
Node.js - Error Handling Patterns
Why should you extend the built-in Error class when creating a custom error in Node.js?
ATo inherit the standard error properties like message and stack trace
BTo automatically log errors to a file
CTo prevent the error from being caught by try-catch blocks
DTo make the error silent and not throw exceptions
Step-by-Step Solution
Solution:
  1. Step 1: Understand Error inheritance

    Extending the built-in Error class allows the custom error to have standard properties like message and stack trace.
  2. Step 2: Recognize benefits of inheritance

    This inheritance ensures the custom error behaves like a normal error and can be caught and logged properly.
  3. Final Answer:

    To inherit the standard error properties like message and stack trace -> Option A
  4. Quick Check:

    Extending Error = inherit properties [OK]
Quick Trick: Always extend Error to keep standard error features [OK]
Common Mistakes:
  • Forgetting to extend Error class
  • Assuming custom errors log automatically
  • Thinking custom errors are silent by default

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes