#include <iostream>

using namespace std;

class A
{
    public:
        A()
        {
            cout<<"A init"<<endl;
            showptr();
            cout<<"throwing..."<<endl;
            throw 1;
        }
        ~A()
        {
            cout<<"A deinit"<<endl;
            showptr();
        }

        void showptr()
        {
            cout<<"A "<<this<<endl;
        }
};

class B
{
    public:
        B() : ClassChain(NULL)
        {
            ClassChain = new A;
            cout<<"B init"<<endl;
            showptr();
        }
        ~B()
        {
            cout<<"B deinit"<<endl;
            showptr();
            delete ClassChain;
            ClassChain = NULL;
        }

        A* ClassChain;

        void showptr()
        {
            cout<<"B "<<this<<endl;
        }
};

int main()
{
    B* myClass = NULL;
    try
    {
        myClass = new B;
    }
    //guaranteed throw
    catch(int)
    {
        delete myClass;
        myClass = NULL;
    }
    return 0;
}