Extend the Error class to create custom error types for your application. This helps callers handle specific error cases.
class ValidationError extends Error {
constructor(message) {
super(message);
this.name = "ValidationError";
}
}
throw new ValidationError("Email is invalid");
Custom errors make your API clearer and debugging easier.