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: chip at atlantic dot net
- Date: Mon, 27 Oct 1997 15:09:52 -0500 (EST)
- Cc: chip at pobox dot com, pkoning at xedia dot com, egcs at cygnus dot com
- Reply-To: chip at pobox dot com
According to ernst.molitor@uni-bonn.de:
> :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...
A delete operator can be called without calling the destructor. That
is, in fact, what the draft ANSI standard requires, when a constructor
of an object created with 'new Class' throws an exception.
--
Chip Salzenberg - a.k.a. - <chip@pobox.com>
"He's Mr. Big of 'Big And Tall' fame." // MST3K