home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!elroy.jpl.nasa.gov!ames!haven.umd.edu!darwin.sura.net!jvnc.net!yale.edu!ira.uka.de!slsvaat!josef!kanze
- From: kanze@us-es.sel.de (James Kanze)
- Subject: Re: Two things: typeof() and exceptions
- In-Reply-To: mccauleyba@vax1.bham.ac.uk's message of Mon, 16 Nov 1992 20:20:36 GMT
- Message-ID: <KANZE.92Nov18154311@slsvdnt.us-es.sel.de>
- Sender: news@us-es.sel.de
- Organization: SEL
- References: <MCGRANT.92Nov15134127@rascals.stanford.edu>
- <1992Nov16.202036.1@vax1.bham.ac.uk>
- Date: 18 Nov 92 15:43:11
- Lines: 50
-
- In article <1992Nov16.202036.1@vax1.bham.ac.uk>, Brian McCauley
- writes:
-
- |> > Secondly, I was reading the reference manual for Dylan (Apple's new OO
- |> > language) and I noticed something that was pretty hot in the exception-
- |> > handling domain. Basically, in any given procedure you can define a set
- |> > of instructions that are guaranteed to be executed even if the rest of
- |> > the procedure is terminated early due to an exception. Currently in C++,
- |> > automatic variables are destroyed as the stack is unwound. But, with
- |> > a set of 'unwind' statements in a function, I could destroy all of the
- |> > variables I allocated on the heap as well.
-
- |> Yes? In C++ this is written thus:
-
- |> void foo() {
- |> try { /* body of function */ }
- |> catch (...) { /* unwinding code */ throw; }
- |> }
-
- |> I'm sure the answer to your question can't be that simple so perhaps
- |> you'd better explain again.
-
- I don't know what Dylan does, but Modula-3 has a finally clause in
- addition to a catch for a try block.
-
- The difference is: a catch clause is only executed if an exception is
- thrown. If it is used for ressource clean-up, then the clean up code
- must be duplicated outside of the catch clause. A finally clause is
- executed whether or not an exception is thrown, so it is sufficient to
- put any clean-up code there. (It also rethrows any exception
- automatically, so the "throw" isn't necessary either.)
-
- Would there be any support for adding a finally clause to C++. It's
- not likely to break any existing code, since it is a pure extension
- (to exceptions, no less; how many people are actually using exceptions
- at this time, as opposed to the number who wish they could?). Except
- for the new keyword, I don't see anything that it could break (just
- offhand, I haven't done any real analysis).
-
- I know that the same effect can be obtained by declaring anything
- requiring clean-up as a class, and doing the clean-up in the
- destructor, but I'm not sure that this is always the most appropriate
- idiom.
- --
- James Kanze GABI Software, Sarl.
- email: kanze@us-es.sel.de 8 rue du Faisan
- 67000 Strasbourg
- France
-
-
-