home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!stanford.edu!EE.Stanford.EDU!sierra!mcgrant
- From: mcgrant@rascals.stanford.edu (Michael C. Grant)
- Subject: Re: TRY ... FINALLY
- In-Reply-To: reindorf@us-es.sel.de's message of Fri, 18 Dec 92 09:46:24 GMT
- Message-ID: <MCGRANT.92Dec18050954@rascals.stanford.edu>
- Sender: usenet@EE.Stanford.EDU (Usenet)
- Organization: Information Systems Laboratory, Stanford University
- References: <1992Dec18.094624.28329@us-es.sel.de>
- Date: 18 Dec 92 05:09:54
- Lines: 33
-
- In article <1992Dec18.094624.28329@us-es.sel.de>
- reindorf@us-es.sel.de (Charles Reindorf) writes:
-
- I have actually seen a post, I think on this newsgroup, concerning the equivalent
- to Modula 3's TRY ... FINALLY clause. (This is exception handling related)
-
- If you have :
- TRY
- statements1
- FINALLY
- statements2
- END
-
- "statements1" gets executed follwed by "statements2" but, if an exception
- gets raised executing "statements1" then "statements2" gets executed before
- re-throwing.
- The important point here is that ANY exit from the TRY
- block results in "statements2" being executed, this includes the equivalent
- of returns, branches, break, continue, and normal exit from the loop. It is
- therefore *not* equivalent to the C++ example ...
-
- Yep, it's also called unwind-protect in lisp dialects... and it makes sense
- to call it that, because after FINALLY are PROTECTED statements in that
- they are executed when the stack is UNWOUND, even for non-local exits.
-
- I suppose it could be simulated by creating a local automatic version of
- a class containing as its destructor any 'statement2' you wish. But, the
- downside is that any variable it accesses must be enclosed inside that
- class. Too bad.
-
- Michael C. Grant
- --
- "Long hair, short hair--what's the difference once the head's blowed off?" (?)
-