I've read that awesome summary of Michael Burr regarding a constructor that throws an exception, here: Will the below code cause memory leak in c++
My question is: Is the behavior similar when an exception is thrown by a function called from constructor? i.e. in case that the exception isn't caught where it was thrown and thus it climbs up to the constructor and further to the function that called to the constructor.
I'm especially interested to know what about the member objects contained in that object's class, will their destructors be called? More specifically, in my case it's about a member of type boost::shared_ptr.
Consider the following example:
class A {
A() { throw some_exception }
};
class B {
B() { A a = new A(); }
};
class C {
boost::shared_ptr<B> p2b;
int i;
int *pint;
someclass objsomeclass;
someclass* psomeclass;
public:
C() {
objsomeclass = someclass();
psomeclass = new someclass();
pint = new int();
p2b(new B);
}
};
void foo()
{
C c();
}
main()
{
foo();
}
Will the destructor of p2a be called? I'll appreciate if you could point me to an appropriate and reliable resource that covers this case.