Exceptions in constructor?
Mike Stump
mrs@wrs.com
Mon Oct 27 18:40:00 GMT 1997
> Date: Mon, 27 Oct 1997 09:19:43 -0500
> From: Paul Koning <pkoning@xedia.com>
> To: chip@pobox.com
> Cc: egcs@cygnus.com
> >>>>> "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.
Be surprised then!
2 An object that is partially constructed will have destructors executed
only for its fully constructed sub-objects. Should a constructor for
an element of an automatic array throw an exception, only the
constructed elements of that array will be destroyed. If the object
or array was allocated in a new-expression and the new-expression
does not contain a new-placement, the deallocation function (3.7.3.2,
12.5) is called to free the storage occupied by the object; the
deallocation function is chosen as specified in 5.3.4. If the object
or array was allocated in a new-expression and the new-expression
contains a new-placement, the storage occupied by the object is
deallocated only if an appropriate placement operator delete is found,
as specified in 5.3.4.
You don't have to speculate what the standard says, just read it. It
is online at http://www.cygnus.com/misc/wp/dec96pub/ . Speculating
that the standard doesn't say things that is says just confuses others
that don't know what it says.
More information about the Gcc
mailing list