2 var captureStackTrace = require('capture-stack-trace');
4 function inherits(ctor, superCtor) {
5 ctor.super_ = superCtor;
6 ctor.prototype = Object.create(superCtor.prototype, {
16 module.exports = function createErrorClass(className, setup) {
17 if (typeof className !== 'string') {
18 throw new TypeError('Expected className to be a string');
21 if (/[^0-9a-zA-Z_$]/.test(className)) {
22 throw new Error('className contains invalid characters');
25 setup = setup || function (message) {
26 this.message = message;
29 var ErrorClass = function () {
30 Object.defineProperty(this, 'name', {
36 captureStackTrace(this, this.constructor);
38 setup.apply(this, arguments);
41 inherits(ErrorClass, Error);