-1 in my real-world experience, JSON.parse and nodejs fs.readFileSync are the only 2 common use-cases that would benefit from this. its more practical to use helper-functions for those 2 use-cases rather than change the javascript language yet again (besides, returning an empty string is commonly more useful for me than returning undefined for failed fs.readFileSync).
this is also a likely footgun that would get abused by novice programmers for many inappropriate use-cases. On Aug 2, 2017 11:59 AM, "Sheng TIAN" <[email protected]> wrote: > Is there any proposal for an one unary operator for ignoring any > exceptions. > > (I have not search out any related threads. But it is useful IMO, so I'm > wondering if this had been discussed.) > > For example, we may introduce an unary operator called `try` which > > 1. calculate the operand first > 2. if it not throw, return as is > 3. otherwise return undefined > > This operator may be used when exceptions should always be ignored. > > Example: > > let resp; > try { > resp = JSON.parse(xhr.responseText); > } catch (_ignore) { /* do nothing here */ } > > may be simplified to: > > const resp = try JSON.parse(xhr.responseText); > > Another Example: > > var age = user && user.age; > > to: > > var age = try user.age; > > (Note, in such case, if operand is start with curly braces "{", it must > be wrapped in parentheses "()".) > > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss > >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

