an operator for ignoring any exceptions
Jordan Harband
ljharb at gmail.com
Fri Aug 11 17:51:12 UTC 2017
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 <michalwadas at gmail.com> 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 <
> 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
>>
>>
>
> _______________________________________________
> 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/ce59a842/attachment-0001.html>
More information about the es-discuss
mailing list