try without catch or finally

Michael A. Smith michael at smith-li.com
Wed Apr 18 05:10:02 PDT 2012


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.kalliokoski at 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 at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>


More information about the es-discuss mailing list