This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Exceptions in constructor?
- To: ernst dot molitor at uni-bonn dot de
- Subject: Re: Exceptions in constructor?
- From: "John A. Tamplin" <jat at traveller dot com>
- Date: Mon, 27 Oct 1997 17:11:48 -0600 (CST)
- cc: egcs at cygnus dot com
On Mon, 27 Oct 1997 ernst.molitor@uni-bonn.de wrote:
> 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...).
You are referring to the case of exceptions occuring within a constructor,
being thrown past the block where the object being constructed lives, and
the destructor not being called since the object is not completely
constructed. I believe the original post was referring to how the compiler
builds a default constructor, in that it should catch exceptions after
memory is allocated and free that memory before passing any exceptions to
the caller. If an exception occurs in operator new, it needs to catch that
exception and clean up after itself before passing it up the chain.
John Tamplin Traveller Information Services
jat@Traveller.COM 2104 West Ferry Way
205/883-4233x7007 Huntsville, AL 35801