JSFiddle - React, Tailwind, and code Playground
by rushtonmd
HTML
<button id="gogo">GO!</button>
<div id="message"></div>
JavaScript
// Custom Errors
function MyCustomError(message) {
this.name = "MyCustomError";
this.message = (message || "");
}
MyCustomError.prototype = Error.prototype;
// Rad function that fails
function superRadFunction(value) {
throw new MyCustomError("Rad function fizzle.");
}
// Wirin' up stuff
$('#gogo').on('click', function (event) {
try {
var returnMessage = superRadFunction("Boom.");
$('#message').html(returnMessage);
} catch (error) {
// you can process the error here if needed
// if (error instanceof MyCutomError) do fancy processing
alert("WARNING! " + error.name + " : " + error.message);
}
});