JSFiddle - React, Tailwind, and code Playground

by James Greene

HTML

<h1>ErrorTypes</h1>
<table border="1">
    <tr>
        <th>EType</th>
        <th>ctor io Error</th>
        <th>io Error</th>
        <th>io EType</th>
        <th>typeof EType</th>
        <th>EType.name</th>
        <th>toString.call</th>
        <th>toString</th>
   </tr>
</table>

CSS

td, th {
    padding: 2px;
}

JavaScript

var $body = $("table");

function appendInfo(i, EType) {
    var instance = new EType("blah");
    var info = {
        ctorIOE: EType instanceof Error,
        instIOE: instance instanceof Error,
        instIOEType: instance instanceof EType,
        typeofEType: typeof EType,
        namedEType: EType.name,
        strCall: Object.prototype.toString.call(instance),
        str: instance.toString()
    };
    var infoArr = [info.ctorIOE, info.instIOE, info.instIOEType, info.typeofEType, info.namedEType, info.strCall, info.str];
    $body.append("<tr><td>" + instance.name + "</td><td>" + infoArr.join("</td><td>") + "</td></tr>");
}

function MyCustomError1() {}
MyCustomError1.prototype = new Error();
MyCustomError1.prototype.constructor = MyCustomError1;

function MyCustomError2() {
    this.name = "MyCustomError2";
};
MyCustomError2.prototype = new Error();
MyCustomError2.prototype.constructor = MyCustomError2;

function MyNonErrorObject() {
    this.name = "MyNonErrorObject";
};

$.each(
    [Error, TypeError, SyntaxError, ReferenceError, RangeError, URIError, EvalError, MyCustomError1, MyCustomError2, MyNonErrorObject],
    appendInfo
);