an operator for ignoring any exceptions

Hikaru Nakashima oao.hikaru.oao at gmail.com
Fri Aug 11 08:16:51 UTC 2017


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?" ?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170811/1e2edb52/attachment.html>


More information about the es-discuss mailing list