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

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