Topic: exceptions during array destruction (using delete[])
Author: Greg Alexander <greg@dignus.com>
Date: Thu, 29 Nov 2001 16:44:10 GMT Raw View
What is supposed to happen when an exception gets thrown by a destructor
during array destruction with delete[]? If an exception is caught from
a destructor is the rest of the array's destructors still called, and
will the entire array's storage still be cleaned up?
For example, suppose I have a three-element array. If destruction of
element number 2 fails then it would be nice if elements 0 and 1 could
still be destructed and it seems important that the entire array would
still be deallocated. However, what if, after receiving an exception
for element number 2, it then receives an exception for element number 1,
will it still go on to attempt element number 0? Presumably the
exception handler that caught the exception for element number 2 intends
to rethrow the exception, but what happens to the exception caught for
element number 1?
A similar situation arises during construction of arrays. If an element
constructor throws an exception then every element that successfully
constructed gets destructed (and any allocated memory gets freed), then
the exception gets rethrown. What happens if one of the destructors
throws an exception inside of the exception handler? Does this exception
go straight to the user, aborting the destruction?
I have dug around some in the standard document and couldn't find any
mention of these situations, so if anyone could point me to the section
of the standard pertaining to exceptions during array
construction/destruction that would be greatly appreciated.
Thanks!
- Greg
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]