home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 12980 < prev    next >
Encoding:
Text File  |  1992-08-27  |  1.8 KB  |  51 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: <1992Aug27.005214.569@frumious.uucp>
  6. Date: Thu, 27 Aug 1992 00:52:14 GMT
  7. Reply-To: uunet.ca!frumious!pat
  8. References: <rmartin.714756719@thor> <1992Aug26.040955.593@frumious.uucp> <BtKuK7.n2G@well.sf.ca.us>
  9. Organization: None
  10. Lines: 39
  11.  
  12. johnrp@well.sf.ca.us (John Panzer) writes:
  13. |In article <1992Aug26.040955.593@frumious.uucp> uunet.ca!frumious!pat writes:
  14. |>An error function that stops your program alters the control flow
  15. |>in a nice, simple way.  By contrast, exceptions can have somewhat
  16. |>non-intuitive effects.  Consider this function:
  17. |>
  18. |>   void foo() {
  19. |>      char* p = new char[17];
  20. |>      doSomething();
  21. |>      delete [] p;
  22. |>   };
  23. |>
  24. |>If doSomething() can throw an exception, then foo() has a memory leak!
  25. |
  26. |If doSomething() calls exit(), the program still has a memory leak.
  27. |(Usually the memory is reclaimed by the system so you don't notice,
  28. |but try it with shared memory sometime...)
  29.  
  30. A good point.  But in most programs one doesn't have to worry about
  31. such things.  Then again, maybe when exceptions are available most
  32. programs won't catch exceptions - they'll just let the program
  33. stop (hopefully with a suitable error message).  So perhaps this
  34. aspect of exceptions won't cause problems for too many people.
  35.  
  36.  
  37. |On the other hand,
  38. |in the presence of exceptions you have at least two ways to plug
  39. |the leak:
  40.  
  41. Quite true.  I wasn't trying to say that exceptions are bad (on the
  42. contrary, I wish I had a compiler that implemented them!).
  43. My point was that they have the potential to play games with
  44. the control flow of one's programs - even in code that doesn't
  45. appear to involve exceptions at all.
  46.  
  47. -- 
  48. Patrick Smith
  49. uunet.ca!frumious!pat
  50. pat%frumious.uucp@uunet.ca
  51.