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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!caen!spool.mu.edu!umn.edu!csus.edu!borland.com!pete
  3. From: pete@borland.com (Pete Becker)
  4. Subject: Re: TRY ... FINALLY
  5. Message-ID: <1992Dec18.172233.18001@borland.com>
  6. Originator: pete@genghis.borland.com
  7. Keywords: Exception Handling TRY FINALLY
  8. Sender: news@borland.com (News Admin)
  9. Organization: Borland International
  10. References: <1992Dec18.094624.28329@us-es.sel.de>
  11. Date: Fri, 18 Dec 1992 17:22:33 GMT
  12. Lines: 30
  13.  
  14. In article <1992Dec18.094624.28329@us-es.sel.de> reindorf@us-es.sel.de (Charles Reindorf) writes:
  15. >
  16. >The important point here is that ANY exit from the TRY block results in "statements2"
  17. >being executed, this includes the equivalent of returns, branches, break, continue,
  18. >and normal exit from the loop. It is therefore *not* equivalent to the C++ example ...
  19. >
  20. >
  21. >   try
  22. >   {
  23. >       statements1
  24. >   }
  25. >   catch(...)
  26. >   {   statements2
  27. >       throw;
  28. >   }
  29. >
  30. >Is there any proposal in the ANSI C++ committee to introduce some sort of "TRY ... FINALLY"
  31. >type of clause into C++. I have found that this is an extremely useful construct (even
  32. >in the absence of exceptions) for putting general "clean-up" code in the "statements2" section
  33. >which frees up new'ed memory, resets state variables, and so-forth. I cannot think of any
  34. >other concise and wieldy way of doing it.
  35. >
  36.  
  37.     Code that must be executed whenever a function returns can be put
  38. in a destructor.  Since such code is typically cleaning up things that were
  39. done earlier in the same function, that probably means that the earlier stuff
  40. should have been done in a constructor.  Which, in turn, means that you're
  41. dealing with a class.
  42.     -- Pete
  43.  
  44.