home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!caen!spool.mu.edu!yale.edu!ira.uka.de!slsvaat!us-es.sel.de!reindorf
- From: reindorf@us-es.sel.de (Charles Reindorf)
- Subject: TRY ... FINALLY
- Message-ID: <1992Dec18.094624.28329@us-es.sel.de>
- Keywords: Exception Handling TRY FINALLY
- Sender: news@us-es.sel.de
- Organization: SEL-Alcatel Line Transmission Systems Dept. US/ES
- Date: Fri, 18 Dec 92 09:46:24 GMT
- Lines: 44
-
- 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 ...
-
-
- try
- {
- statements1
- }
- catch(...)
- { statements2
- throw;
- }
-
- Is there any proposal in the ANSI C++ committee to introduce some sort of "TRY ... FINALLY"
- type of clause into C++. I have found that this is an extremely useful construct (even
- in the absence of exceptions) for putting general "clean-up" code in the "statements2" section
- which frees up new'ed memory, resets state variables, and so-forth. I cannot think of any
- other concise and wieldy way of doing it.
-
- Any comments?
-
-
- Charles Reindorf
-
-
-