JSFiddle - React, Tailwind, and code Playground

by Joshua Koudys

JavaScript

function UserException(message) {
    this.message = message;
}

function checkANumber(num) {
    if (num < 100) {
        throw new UserException("My fancy exception");
    } else if (num > 1000000) {
        throw "Some plebian string.";
    }
    return true;
}

try {
    if (checkANumber(10000000000000000000000)) {
        alert("Success!");
    }
} catch (e) {
    if (e instanceof UserException) {
        alert("Please enter a nicer number.");
    } else {
        throw e;
    }
} finally {
    console.log("Finally!");
}

console.log("I'm at the bottom!");