One line of code which is specific in what it catches:<p><pre><code> // Either foo or someError will be defined
const [foo, someError] = itry(someFn, SomeError);
</code></pre>
Instead of nine lines which feel like they are working uphill against the language: dealing with variable scoping issues, deeper nesting, and footguns like forgetting to re-throw.<p><pre><code> let foo;
try {
foo = someFn();
} catch (err) {
if (err instanceof SomeError) {
// do something with error
} else {
throw err;
}
}
// use foo</code></pre>