Allow `try…catch` blocks to return a value.
# Gary Guo (9 years ago)
This is not possible as it contracts with existing semantics. Wrap it with a function instead.
This is not possible as it contracts with existing semantics. Wrap it with a function instead. From: jbucaran at me.com Subject: Allow `try…catch` blocks to return a value. Date: Sun, 12 Jul 2015 06:53:52 +0900 To: es-discuss at mozilla.org Allow `try…catch` blocks to return a value.Sometimes I wrap a `try…catch` in a function and return a value based in whether there was an error or not.It would be useful if you could use `return` inside a `try…catch` block to accomplish the same.```js let stuff = try { return ... } catch (e) { return … ? … : ... }``` _______________________________________________ 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/20150712/9b864923/attachment-0001.html>
# Andreas Rossberg (9 years ago)
Do-expressions will solve this:
let stuff = do { try {
f()
} catch (e) { 0 } }
The inflation of braces is somewhat ugly there, and we might want to allow dropping some of them.
Do-expressions will solve this: let stuff = do { try { f() } catch (e) { 0 } } The inflation of braces is somewhat ugly there, and we might want to allow dropping some of them. /Andreas On 12 July 2015 at 10:26, Gary Guo <nbdd0121 at hotmail.com> wrote: > This is not possible as it contracts with existing semantics. Wrap it with > a function instead. > > ------------------------------ > From: jbucaran at me.com > Subject: Allow `try…catch` blocks to return a value. > Date: Sun, 12 Jul 2015 06:53:52 +0900 > To: es-discuss at mozilla.org > > > Allow `try…catch` blocks to return a value. > > Sometimes I wrap a `try…catch` in a function and return a value based in > whether there was an error or not. > > It would be useful if you could use `return` inside a `try…catch` block to > accomplish the same. > > > ```js > let stuff = try { > return ... > } catch (e) { return … ? … : ... } > ``` > _______________________________________________ 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/20150713/3d2eb3b4/attachment-0001.html>
# Michał Wadas (9 years ago)
let stuff = ()=>{ try {
return f();
} catch(e){ return f; } }();
14 chars more.
let stuff = ()=>{ try { return f(); } catch(e){ return f; } }(); 14 chars more. 2015-07-13 10:14 GMT+02:00 Andreas Rossberg <rossberg at google.com>: > Do-expressions will solve this: > > let stuff = do { try { > f() > } catch (e) { 0 } } > > The inflation of braces is somewhat ugly there, and we might want to allow > dropping some of them. > > /Andreas > > > On 12 July 2015 at 10:26, Gary Guo <nbdd0121 at hotmail.com> wrote: >> >> This is not possible as it contracts with existing semantics. Wrap it with >> a function instead. >> >> ________________________________ >> From: jbucaran at me.com >> Subject: Allow `try…catch` blocks to return a value. >> Date: Sun, 12 Jul 2015 06:53:52 +0900 >> To: es-discuss at mozilla.org >> >> >> Allow `try…catch` blocks to return a value. >> >> Sometimes I wrap a `try…catch` in a function and return a value based in >> whether there was an error or not. >> >> It would be useful if you could use `return` inside a `try…catch` block to >> accomplish the same. >> >> >> ```js >> let stuff = try { >> return ... >> } catch (e) { return … ? … : ... } >> ``` >> _______________________________________________ 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 >> > > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss >
# Bucaran (9 years ago)
Exactly, but the reason I proposed this is because the method your are describing was not satisfactory enough / I found it inconvenient.
Exactly, but the reason I proposed this is because the method your are describing was not satisfactory enough / I found it inconvenient. Regards > On Jul 13, 2015, at 6:00 PM, Michał Wadas <michalwadas at gmail.com> wrote: > > let stuff = ()=>{ try { > return f(); > } catch(e){ return f; } }(); > 14 chars more. > > > 2015-07-13 10:14 GMT+02:00 Andreas Rossberg <rossberg at google.com>: >> Do-expressions will solve this: >> >> let stuff = do { try { >> f() >> } catch (e) { 0 } } >> >> The inflation of braces is somewhat ugly there, and we might want to allow >> dropping some of them. >> >> /Andreas >> >> >> On 12 July 2015 at 10:26, Gary Guo <nbdd0121 at hotmail.com> wrote: >>> >>> This is not possible as it contracts with existing semantics. Wrap it with >>> a function instead. >>> >>> ________________________________ >>> From: jbucaran at me.com >>> Subject: Allow `try…catch` blocks to return a value. >>> Date: Sun, 12 Jul 2015 06:53:52 +0900 >>> To: es-discuss at mozilla.org >>> >>> >>> Allow `try…catch` blocks to return a value. >>> >>> Sometimes I wrap a `try…catch` in a function and return a value based in >>> whether there was an error or not. >>> >>> It would be useful if you could use `return` inside a `try…catch` block to >>> accomplish the same. >>> >>> >>> ```js >>> let stuff = try { >>> return ... >>> } catch (e) { return … ? … : ... } >>> ``` >>> _______________________________________________ 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 >>> >> >> >> _______________________________________________ >> 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
Allow
try…catch
blocks to return a value.Sometimes I wrap a
try…catch
in a function and return a value based in whether there was an error or not.It would be useful if you could use
return
inside atry…catch
block to accomplish the same.let stuff = try { return ... } catch (e) { return … ? … : ... }