Thread View: comp.std.c++
2 messages
2 total messages
Started by James Kanze US/ESC 60/3/141 #407...
Mon, 06 Nov 1995 21:09
Exceptions in destructors.
Author: James Kanze US/ESC 60/3/141 #407...
Date: Mon, 06 Nov 1995 21:09
Date: Mon, 06 Nov 1995 21:09
45 lines
2170 bytes
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. ]
Re: Exceptions in destructors.
Author: John Max Skaller
Date: Thu, 09 Nov 1995 10:13
Date: Thu, 09 Nov 1995 10:13
59 lines
2111 bytes
2111 bytes
James Kanze US/ESC 60/3/141 #40763 <kanze@lts.sel.alcatel.de> wrote:
>
>
>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.
I agree. "Stack unwinding" and "object unwinding"
(destruction) are closely related. If during destruction
an exception is thrown, destruction continues (provided
there is a reachable handler)
>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?
Good point. That kind of makes it necessary that
a scheduled dealloctation occur, despite any exception
thrown. As if:
delete p;
meant:
try { p->~P(); }
catch(...) {
operator delete(p);
throw;
}
operator delete(p);
[Smly for array case?]
--
John Max Skaller voice: 61-2-566-2189
81 Glebe Point Rd fax: 61-2-660-0850
GLEBE NSW 2037 email: maxtal@suphys.physics.oz.au
AUSTRALIA email: skaller@maxtal.com.au
---
[ 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. ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads