JSFiddle - React, Tailwind, and code Playground

by Artem

JavaScript

var SpecificError = Object.create(Error.prototype);
SpecificError.constructor = function(message) {
  this.name = 'Specific Error';
  this.message = message;
  this.stack = (new Error).stack;
  return this;
};
SpecificError.constructor.prototype = SpecificError;

var OtherError = Object.create(SpecificError);
OtherError.constructor = function(message) {
	SpecificError.constructor.apply(this, arguments);
  this.name = 'Other Error';
};

try {
  throw new OtherError.constructor('Very specific error');
} catch (e) {
  if (e instanceof OtherError.constructor)
    console.log(e);
  else
    throw e;
}