scmJS docs

Errors

try, catch, finally and throw work as in TypeScript. throw takes a new Error(…), a RangeError, a TypeError, a class that extends one of them, or what a catch took (throw e). A class of error has a message, a name and fields of its own, and e instanceof OutOfGold tells the classes apart.

class OutOfGold extends Error {
  constructor(public need: number) { super(`need ${need} more`); }
}

program(() => {
  let gold = 30;
  function buy(cost: number) {
    if (cost > gold) throw new OutOfGold(cost - gold);
    gold -= cost;
  }
  try {
    buy(20);
    buy(50);
  } catch (e) {
    if (e instanceof OutOfGold) print(`${e.message} (${e.need})`);   // need 40 more (40)
    else throw e;
  } finally {
    print(`${gold} left`);                      // 10 left
  }
});