JSFiddle - React, Tailwind, and code Playground

by TheDiamondDoge

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);
}