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: <1992Aug26.040955.593@frumious.uucp>
- Date: Wed, 26 Aug 1992 04:09:55 GMT
- Reply-To: uunet.ca!frumious!pat
- References: <rmartin.714669410@thor> <1992Aug25.034553.575@frumious.uucp> <rmartin.714756719@thor>
- Organization: None
- Lines: 42
-
- rmartin@thor.Rational.COM (Bob Martin) writes:
-
- |No, exceptions do not violate structure (IMHO). The function which
- |throws an exception never returns! The calling code preserves its
- |invariants. The exception is caught by code which expects it, so its
- |invariants are not violated either.
- |
- |Nor do exceptions violate single entry single exit, since the
- |exception is not an exit, it does not return to the caller. Rather it
- |is caught by a higher level catch which is itself written in a
- |structured block.
-
- 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!
- The same is true if doSomething() can call longjmp(), but when
- exceptions become commonly available, I suspect they will be much more
- widely used than longjmp().
-
-
-
- Since I'm already posting, I'll take this opportunity to correct
- a mistake in my earlier post...
-
- ||Ideally, the author and the reader share the same assumptions,
- ||but that's not often true.
-
- That should have read "... but that's often not true."
- A small typo, but one with a significant effect on the meaning.
-
- --
- Patrick Smith
- uunet.ca!frumious!pat
- pat%frumious.uucp@uunet.ca
-