home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 12891 < prev    next >
Encoding:
Text File  |  1992-08-25  |  1.8 KB  |  54 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!uunet.ca!frumious!pat
  3. From: pat@frumious.uucp (Patrick Smith)
  4. Subject: Re: break/continue (was: Re: Tiny proposal for named loops.)
  5. Message-ID: <1992Aug26.040955.593@frumious.uucp>
  6. Date: Wed, 26 Aug 1992 04:09:55 GMT
  7. Reply-To: uunet.ca!frumious!pat
  8. References: <rmartin.714669410@thor> <1992Aug25.034553.575@frumious.uucp> <rmartin.714756719@thor>
  9. Organization: None
  10. Lines: 42
  11.  
  12. rmartin@thor.Rational.COM (Bob Martin) writes:
  13.  
  14. |No, exceptions do not violate structure (IMHO).  The function which
  15. |throws an exception never returns!  The calling code preserves its
  16. |invariants.  The exception is caught by code which expects it, so its
  17. |invariants are not violated either.
  18. |
  19. |Nor do exceptions violate single entry single exit, since the
  20. |exception is not an exit, it does not return to the caller.  Rather it
  21. |is caught by a higher level catch which is itself written in a
  22. |structured block.
  23.  
  24. An error function that stops your program alters the control flow
  25. in a nice, simple way.  By contrast, exceptions can have somewhat
  26. non-intuitive effects.  Consider this function:
  27.  
  28.    void foo() {
  29.       char* p = new char[17];
  30.       doSomething();
  31.       delete [] p;
  32.    };
  33.  
  34. If doSomething() can throw an exception, then foo() has a memory leak!
  35. The same is true if doSomething() can call longjmp(), but when
  36. exceptions become commonly available, I suspect they will be much more
  37. widely used than longjmp().
  38.  
  39.  
  40.  
  41. Since I'm already posting, I'll take this opportunity to correct
  42. a mistake in my earlier post...
  43.  
  44. ||Ideally, the author and the reader share the same assumptions,
  45. ||but that's not often true.
  46.  
  47. That should have read "... but that's often not true."
  48. A small typo, but one with a significant effect on the meaning.
  49.  
  50. -- 
  51. Patrick Smith
  52. uunet.ca!frumious!pat
  53. pat%frumious.uucp@uunet.ca
  54.