🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2440

Exceptions in destructors.

#2440
From: James Kanze US/ESC 60/3/141 #407...
Date: Mon, 06 Nov 1995 21:09
45 lines
2170 bytes

While trying to implement an exception-safe array class (and model it
on the built-in C style arrays as closely as possible), it occured to
me that the draft doesn't really have much to say about the case of
exceptions thrown in destructors.  Two cases occur to me:

1. Given:

	T               a[ 5 ] ;

When destructing the third element (for example), an exception is
thrown.  Are the remaining elements destructed?  I would say yes.  The
words concerning partially constructed objects in 15.2 would seem to
sort of agree, but I would be happier if their was at least a footnote
to indicate that `partially constructed' objects also occur as a
result of partial destruction.

2. Given:

	T*              pa = new T[ 5 ] ;
	//  ...
	delete [] pa ;

Again, an exception when destructing the third element of the array
pointed to by pa, in the delete expression.  The above question is
obviously still valid, but in addition: does the memory get freed
(operator delete[] get called)?  I can find nothing in the draft
standard to indicate that it does, but if it doesn't, how does one go
about freeing it later?  (Calling operator delete[] directly is
illegal, since the pointer `pa' is not required to be, and often
isn't, the value returned by operator new[].)
--

James Kanze         Tel.: (+33) 88 14 49 00        email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils en informatique industrielle --
                              -- Beratung in industrieller Datenverarbeitung



---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <9511061549.AA15364@lts.sel.alcatel.de>
Path: arc1-ca.pugleaf.net!128.32.155.1!matt

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
From: James Kanze US/ESC 60/3/141 #40763 <kanze@lts.sel.alcatel.de>
Newsgroups: comp.std.c++
Subject: Exceptions in destructors.
Date: 06 Nov 1995 21:09:16 GMT
Organization: <none>
Approved: matt@physics2.Berkeley.EDU (Matt Austern)
Message-ID: <9511061549.AA15364@lts.sel.alcatel.de>
NNTP-Posting-Host: physics2.berkeley.edu