Standardizing conditional try/catch

Zach Lym zachlym at
Sat Mar 18 00:01:49 UTC 2017

Firefox supports the following conditional `catch` syntax:

    try {
        let result = await ();
    } catch (e if e instanceof ErrorType) {

This was originally implemented in Spidermonkey as part of an ES proposal
around 2000, but it was rejected for unknown reasons [0]. A 2012 email to
this list suggesting standardization of the syntax was passed over in favor
of waiting for a generic pattern matching facility [0][1].  Later
discussion suggests that the pattern matching proposal would have been very
slow [2]. A proposal for a Java-like type-based conditional was proposed in
2016, but was criticized for lacking generality [2].

If the above summary is accurate, I would like to try to standardize the
vanilla syntax once again.  It's imperative, general, and doesn't preclude
the use of any hypothetical pattern matching functionality.

Javascript's control flow has improved dramatically in recent years:
promises got rid of callbacks, `async`/`await` clipped promise chains, and
classes make it easy to create custom Error objects that preserve
stacktraces.  Conditional catch is the last bit of syntax needed to make JS
look like it was designed to handle asynchronous functions.


-Zach Lym

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list