catchr
v0.1.0
Published
const assignment even with exceptional code
Readme
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);
}