Suppose I have a pointer to a dynamically allocated array of 10 elements:
T* p = new T[10];
Later, I want to release that array:
delete[] p;
What happens if one of the T destructors throws an exception? Do the other elements still get destructed? Will the memory be released? Will the exception be propagated, or will program execution be terminated?
Similarly, what happens when a std::vector<T> is destroyed and one of the T destructors throws?
I can not see it explicitly called out in the standard:
Just that they will be called in reverse order of creation
5.3.5 Delete [expr.delete]
And that the memory deallocation will be done even if the exception is thrown:
I tried the following code in G++ and it shows that that no more destructors get called after the exception:
Execute:
Which all leads back to this (very old answer):
throwing exceptions out of a destructor