an operator for ignoring any exceptions

Michał Wadas michalwadas at gmail.com
Fri Aug 11 14:13:45 UTC 2017


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 <oao.hikaru.oao at gmail.com
> 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
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170811/fa86cd49/attachment.html>


More information about the es-discuss mailing list