[antlr-interest] Handling 'finally' in language target that doesn't have 'finally'
Rick Mann
rmann at latencyzero.com
Mon Jan 19 12:07:47 PST 2009
On Jan 19, 2009, at 11:53:57, Gavin Lambert wrote:
> There's actually no technical reason (from a language standpoint)
> why "finally" couldn't be supported in C/C++ language targets (apart
> from the fact that there isn't a C++ target yet for v3).
>
> I don't know if it *is* actually supported, but it could be.
Hmm. I thought I had a pretty good grasp of C++. It lacks a "finally"
keyword, which means you implement automatic-code-execution-on-scope-
exit with RAII. This requires instantiating objects on the stack at
appropriate places. This is fine, if sometimes cumbersome, but I
wanted to avoid letting someone put "finally" in their grammar.
On Jan 19, 2009, at 11:56:47, Wacek Kusnierczyk wrote:
> Rick Mann wrote:
>> In a language like C++, which stupidly doesn't support "finally",
>>
> you might want to read what the designers of c++ have to say in this
> matter before you make such judgments:
>
> http://www.research.att.com/~bs/bs_faq2.html#finally
Yeah, I love C++, really, but I disagree with the creators/sustainers
on a few issues. This is one. I love that I can use RAII, and often it
is better, but frequently you have one-off cleanup that is much more
compactly written in a finally clause. There's no good reason not to
have both.
On Jan 19, 2009, at 12:00:29, Sam Harwell wrote:
> I assume you're trying to write a new target? If so, you can do
> something like this, with nested try/catch and a duplication of the
> finally code:
>
> try {
> try {
> <tryCode>
> } catch ( ExceptionType1 ) {
> <handler>
> }
> } catch ( ... ) {
> <finallyCode>
> throw;
> }
> <finallyCode>
An interesting approach, but a bit icky, don't you think? If you can
guarantee a superclass to the exceptions, it could be a bit tidier,
perhaps, but really, C++? Can't we just have finally already? :-)
Anyway, I guess I have my answer. Thanks!
--
Rick
More information about the antlr-interest
mailing list