Re: Proposal: A block between "try" and "catch".
On Jun 10, 9:07 pm, Alexis Guillaume <alexis.c.guilla...@gmail.com>
wrote:
As new syntax proposals seem to be welcomed, here are my two cents :
[snip -- syntax extension for variable declarations]
This would avoid the clutter of an extra out of scope variable, or an
anonymous scope. Plus, I find it quite clear. Yet I'm fairly certain
that this new syntax comes with many problems I didn't foresee, and
I'm curious to know what they are...
It's an interesting idea. Seems like it would be relatively easy to
implement, and does add to the clarity of the purpose of the
variables. Also, it has a parallel to the allowing of declarations in
for() and if() clauses. There are a few things the "throw goto ..."
proposal can do that this can't, but it would address the problem I
was having.
There are two things I don't like about it, although they're somewhat
mild.
First, although it's clearer than what we have now where we need to
declare the necessary variables outside the try block entirely, it
does still require someone reading the code to trace the variable
logic to determine exactly what is being done. It would be nice to
have a construct whose very structural nature makes it clear that the
desire is to rescind "try" protection. Also, although I'm not a
compiler writer (at least not professionally), I'd venture a guess
that a compiler might be able to optimize an explicit code structure
better than an idiom using variables.
Second, because it's equivalent to this (naturally less clear, but
structurally similar) code path, I think it might have trouble getting
traction to be added to the standard:
{
bool do_rethrow=false;
try {---}
catch (---) {---}
}
(On a completely different note, you might observe that in Guillaume's
proposal, use of an "else" clause isn't necessary---after a rethrow,
you can assume you're not in the "catch" logic anymore.)
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]