Relevant existing proposals: - https://github.com/tc39/proposal-optional-catch-binding/
- https://github.com/tc39/proposal-pattern-matching/ On Fri, Aug 11, 2017 at 7:13 AM, Michał Wadas <[email protected]> wrote: > It's extremely unlikely that new syntax will be introduced to replace one > line helper function. Especially after experiences of PHP where > swallow-error operator is a source of eternal torment. > > swallowException = fn => Promise.resolve().then(fn).catch(()=>null) > > On Fri, Aug 11, 2017 at 10:16 AM, Hikaru Nakashima < > [email protected]> wrote: > >> I think this idea is useful in async function. >> >> For exsample, we write codes as below, when we use fetch() in async >> function. >> >> ```js >> >> let res, text >> >> try { >> res = await fetch( url ) >> } catch ( err ) { console.log( 'network error' ) } >> >> if ( ! res.ok ) console.log( 'server error' ) >> else text = await res.text( ) >> >> >> ``` >> >> or >> >> ```js >> >> let res, text >> >> res = await fetch( url ).catch( err => null ) >> if ( ! res ) console.log( 'network error' ) >> >> else if ( ! res.ok ) console.log( 'server error' ) >> else text = await res.text( ) >> >> >> ``` >> >> but, we can write as below if we use this proposal. >> >> ```js >> >> let res, text >> >> res = try await fetch( url ) >> if ( ! res ) console.log( 'network error' ) >> >> else if ( ! res.ok ) console.log( 'server error' ) >> else text = await res.text( ) >> >> ``` >> >> or do we need another syntax like "await?" ? >> >> _______________________________________________ >> 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 > >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

