Open graingert opened 7 years ago
I'd also like to see an implicit catch { }
on try expressions.
const foo = () => do { throw new Error('foo'); };
const bar = () => 3;
const res = do { try { foo(); } } || bar();
console.log(res); // 3;
@graingert This is a bug in Babel, your expectation is correct.
As for the “implicit catch” wish, this is unrelated to this proposal. I’ll just mention that it has been recently discussed on es-discuss: https://esdiscuss.org/topic/an-operator-for-ignoring-any-exceptions
What should happen if there is a finally
block? If it is anything but an empty block, it potentially overrides the completion value of the try
or catch
block, unless any potential completion value of finally
is always ignored.
@Kovensky According to the spec, completion value of a finally
block is ignored, unless it is an abrupt completion.
I expect this to work:
But I get
undefined
;babel transpiles to:
but I expected:
an alternative that works is: