catchr

0.1.0 • Public • Published

Instead of:

let x;
try {
  x = exceptionThrowingFunction();
} catch(ex) {
  x = reasonableDefault;
}
useX(x);

This:

const [x] = catchr(_ => exceptionThrowingFunction(), reasonableDefault);
useX(x);

You can also receive the exception:

const [x, err] = catchr(_ => exceptionThrowingFunction(), reasonableDefault);
if (err.name !== "SyntaxError") {
  useX(x);
}

Readme

Keywords

none

Package Sidebar

Install

npm i catchr

Weekly Downloads

1

Version

0.1.0

License

MIT

Last publish

Collaborators

  • rentzsch