Possible Duplicate:
Is the destructor called if the constructor throws an exception?
I have a question to you. Does destructor is executed, when constructor throws an exception? Sample code:
#include <cstdio>
struct Test
{
Test (void)
{
throw 100;
}
~Test (void)
{
printf ("~Test\n");
}
};
int main (void)
{
try
{
Test test;
}
catch (int value)
{
}
}
When running this code "~Test" is not displayed. Ok, I may understand this behavior. Assume that Test have dynamically allocated members, which are allocated inside constructor and deleted in destructor. What will happen with them, when exceptions is thrown after they were allocated in constructor?