home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!uunet.ca!frumious!pat
- From: pat@frumious.uucp (Patrick Smith)
- Subject: Re: break/continue (was: Re: Tiny proposal for named loops.)
- Message-ID: <1992Aug27.005214.569@frumious.uucp>
- Date: Thu, 27 Aug 1992 00:52:14 GMT
- Reply-To: uunet.ca!frumious!pat
- References: <rmartin.714756719@thor> <1992Aug26.040955.593@frumious.uucp> <BtKuK7.n2G@well.sf.ca.us>
- Organization: None
- Lines: 39
-
- johnrp@well.sf.ca.us (John Panzer) writes:
- |In article <1992Aug26.040955.593@frumious.uucp> uunet.ca!frumious!pat writes:
- |>An error function that stops your program alters the control flow
- |>in a nice, simple way. By contrast, exceptions can have somewhat
- |>non-intuitive effects. Consider this function:
- |>
- |> void foo() {
- |> char* p = new char[17];
- |> doSomething();
- |> delete [] p;
- |> };
- |>
- |>If doSomething() can throw an exception, then foo() has a memory leak!
- |
- |If doSomething() calls exit(), the program still has a memory leak.
- |(Usually the memory is reclaimed by the system so you don't notice,
- |but try it with shared memory sometime...)
-
- A good point. But in most programs one doesn't have to worry about
- such things. Then again, maybe when exceptions are available most
- programs won't catch exceptions - they'll just let the program
- stop (hopefully with a suitable error message). So perhaps this
- aspect of exceptions won't cause problems for too many people.
-
-
- |On the other hand,
- |in the presence of exceptions you have at least two ways to plug
- |the leak:
-
- Quite true. I wasn't trying to say that exceptions are bad (on the
- contrary, I wish I had a compiler that implemented them!).
- My point was that they have the potential to play games with
- the control flow of one's programs - even in code that doesn't
- appear to involve exceptions at all.
-
- --
- Patrick Smith
- uunet.ca!frumious!pat
- pat%frumious.uucp@uunet.ca
-