This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Exceptions in constructor?
- To: chip at pobox dot com
- Subject: Re: Exceptions in constructor?
- From: ernst dot molitor at uni-bonn dot de
- Date: Mon, 27 Oct 1997 17:27:54 GMT
- CC: pkoning at xedia dot com, chip at pobox dot com, egcs at cygnus dot com
- References: <199710271437.JAA28294@cyprus.atlantic.net>
- Reply-to: ernst dot molitor at uni-bonn dot de
Dear discussants,
:According to Paul Koning:
:> >>>>> "chip" == chip <chip@atlantic.net> writes:
:> chip> I'm 99.44% pleased with the exception-based code I can now
:> chip> write and test under Linux on x86. The remaining .56% would be
:> chip> fulfilled if throwing an exception in a constructor
:> chip> automatically called the appropriate operator delete () if
:> chip> there had been a call to operator new ().
:>
:> Does the C++ standard say to do that? It would surprise me.
:
:Of course! Without it, exceptions thrown in (or through) constructors
:would cause irreparable memory leaks.
I don't have the standard at hands, but B. Stroustrup, in his book
"C++ Programming Language" (3rd ed. paperback), states that a
destructor will be called only for objects that are "completely
constructed" (p. 367). Depending on the source code in question, this
may mean that an exception thrown in a constructor will _not_ cause a
call of the destructor, where the call to delete would be expected (an
example is given in the book, with a note that memory leaks may be
caused by this...).
Best regards,
Ernst