Re: try without catch or finally
On 17 April 2012 22:35, Jussi Kalliokoski jussi.kallioko...@gmail.com wrote: I'm not sure if this has been discussed before, but is it a terribly bad idea to make catch/finally optional for a try block? There's a lot of code like this out there: try { /* something here */ } catch (e) { /* nothing here */ } Silent catch-alls like that are almost always bad code. I think the language rather shouldn't encourage this pattern with extra convenience. /Andreas ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: try without catch or finally
Silent catch-alls like that are almost always bad code. I think the language rather shouldn't encourage this pattern with extra convenience. I don't see how this would be much more encouraging than allowing for the catch block to do nothing. The people who would use this would leave the catch block empty anyway. I am also perplexed as to how often things are countered with similar arguments. Incompetent programmers make bad decisions regardless of how much the language/framework/library does to prevent this. In my mind it's not a valid excuse for not making things harder for those who know what they're doing. (And I'm in no way claiming to be a competent developer, this is just an opinion :]) /Andreas ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: try without catch or finally
Why is the argument and curly brace syntax required for except? Why not simply allow: try { throw ExceptionalException; } catch dosubroutine(); which for the convenience of Jussi's original ask: try { //fail } catch null; (or if you prefer, a noop call). The lack of parentheses make it clear that the word following 'except' is not the error parameter, and the lack of braces clearly means the catch-phrase ends at the semicolon. It could even be immediately followed by a finally, which I think yields some terse, but useful syntax that's intuitive and consistent. try foo(); catch bar(); finally cleanUp(); in the same spirit as if (foo) doFoo(); else doBar(); -Michael A. Smith On Wed, Apr 18, 2012 at 5:45 AM, Jussi Kalliokoski jussi.kallioko...@gmail.com wrote: Silent catch-alls like that are almost always bad code. I think the language rather shouldn't encourage this pattern with extra convenience. I don't see how this would be much more encouraging than allowing for the catch block to do nothing. The people who would use this would leave the catch block empty anyway. I am also perplexed as to how often things are countered with similar arguments. Incompetent programmers make bad decisions regardless of how much the language/framework/library does to prevent this. In my mind it's not a valid excuse for not making things harder for those who know what they're doing. (And I'm in no way claiming to be a competent developer, this is just an opinion :]) /Andreas ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
try without catch or finally
I'm not sure if this has been discussed before, but is it a terribly bad idea to make catch/finally optional for a try block? There's a lot of code like this out there: try { /* something here */ } catch (e) { /* nothing here */ } Cheers, Jussi ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: try without catch or finally
It's easy to forget to catch in cases you wanted to. Maybe adding a new keyword: try { ... } drop; 17. април 2012. 13.35, Jussi Kalliokoski jussi.kallioko...@gmail.com је написао/ла: I'm not sure if this has been discussed before, but is it a terribly bad idea to make catch/finally optional for a try block? There's a lot of code like this out there: try { /* something here */ } catch (e) { /* nothing here */ } Cheers, Jussi ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss -- Nebojša Ćirić ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
RE: try without catch or finally
Tangentially related: https://github.com/kriskowal/q/wiki/On-Exceptions From: es-discuss-boun...@mozilla.org [es-discuss-boun...@mozilla.org] on behalf of Nebojša Ćirić [c...@google.com] Sent: Tuesday, April 17, 2012 16:39 To: Jussi Kalliokoski Cc: es-discuss Subject: Re: try without catch or finally It's easy to forget to catch in cases you wanted to. Maybe adding a new keyword: try { ... } drop; 17. април 2012. 13.35, Jussi Kalliokoski jussi.kallioko...@gmail.commailto:jussi.kallioko...@gmail.com је написао/ла: I'm not sure if this has been discussed before, but is it a terribly bad idea to make catch/finally optional for a try block? There's a lot of code like this out there: try { /* something here */ } catch (e) { /* nothing here */ } Cheers, Jussi ___ es-discuss mailing list es-discuss@mozilla.orgmailto:es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss -- Nebojša Ćirić ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: try without catch or finally
I don't think it's really necessary to have another keyword for that just so you wouldn't forget the catch, sounds more like work for a static code analysis tool to me, just like we don't want if (something) doSomething() to throw just because you might have forgotten the curly braces. P.S. Sorry Nebojša for double posting, I always forget reply all! ;) On Tue, Apr 17, 2012 at 11:39 PM, Nebojša Ćirić c...@google.com wrote: It's easy to forget to catch in cases you wanted to. Maybe adding a new keyword: try { ... } drop; 17. април 2012. 13.35, Jussi Kalliokoski jussi.kallioko...@gmail.com је написао/ла: I'm not sure if this has been discussed before, but is it a terribly bad idea to make catch/finally optional for a try block? There's a lot of code like this out there: try { /* something here */ } catch (e) { /* nothing here */ } Cheers, Jussi ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss -- Nebojša Ćirić ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss