xxxxxxxxxx
class CustomError extends Error {
constructor(message) {
super(message);
this.name = 'CustomError';
}
}
// Usage
try {
throw new CustomError("This is a custom error!");
} catch (error) {
if (error instanceof CustomError) {
console.error("Caught a custom error:", error.message);
} else {
console.error("Caught an unknown error:", error.message);
}
}