home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 18169 < prev    next >
Encoding:
Text File  |  1992-12-20  |  1.6 KB  |  56 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!caen!spool.mu.edu!yale.edu!ira.uka.de!slsvaat!us-es.sel.de!reindorf
  3. From: reindorf@us-es.sel.de (Charles Reindorf)
  4. Subject: TRY ... FINALLY
  5. Message-ID: <1992Dec18.094624.28329@us-es.sel.de>
  6. Keywords: Exception Handling TRY FINALLY
  7. Sender: news@us-es.sel.de
  8. Organization: SEL-Alcatel Line Transmission Systems Dept. US/ES
  9. Date: Fri, 18 Dec 92 09:46:24 GMT
  10. Lines: 44
  11.  
  12. I have actually seen a post, I think on this newsgroup, concerning the equivalent
  13. to Modula 3's TRY ... FINALLY clause. (This is exception handling related)
  14.  
  15. If you have :
  16.  
  17.    TRY
  18.  
  19.       statements1
  20.  
  21.    FINALLY
  22.  
  23.       statements2
  24.  
  25.    END
  26.  
  27. "statements1" gets executed follwed by "statements2" but, if an exception gets raised
  28. executing "statements1" then "statements2" gets executed before re-throwing.
  29.  
  30. The important point here is that ANY exit from the TRY block results in "statements2"
  31. being executed, this includes the equivalent of returns, branches, break, continue,
  32. and normal exit from the loop. It is therefore *not* equivalent to the C++ example ...
  33.  
  34.  
  35.    try
  36.    {
  37.        statements1
  38.    }
  39.    catch(...)
  40.    {   statements2
  41.        throw;
  42.    }
  43.  
  44. Is there any proposal in the ANSI C++ committee to introduce some sort of "TRY ... FINALLY"
  45. type of clause into C++. I have found that this is an extremely useful construct (even
  46. in the absence of exceptions) for putting general "clean-up" code in the "statements2" section
  47. which frees up new'ed memory, resets state variables, and so-forth. I cannot think of any
  48. other concise and wieldy way of doing it.
  49.  
  50. Any comments?
  51.  
  52.  
  53. Charles Reindorf
  54.  
  55.  
  56.