Custom Errors & Extending Error
MediumIn plain terms
Extend Error for custom error types. Set name and message. Use instanceof for type checks. Improves error handling clarity.
What you need to know
- •extends Error
- •name, message
- •instanceof
Try it yourself
Copy the code below and run it in your browser console or a code editor:
class ValidationError extends Error { constructor(msg) { super(msg); this.name = 'ValidationError'; } }Learn more
Dive deeper with these trusted resources: