JSFiddle - React, Tailwind, and code Playground
JavaScript
class ValidationError extends Error {
constructor(message) {
super(message); // (1)
this.name = "ValidationError"; // (2)
}
}
function test() {
throw new ValidationError("Упс!");
}
try {
test();
} catch(err) {
alert(err instanceof ValidationError);
}