In below code snippet while throwing exception from Base class's constructor programme got aborted. I believe derive class has already handled exception properly but still programme got terminted and gracefull exit from programme didn't happen. Could you let me know what wrong with this approach as if exception is handled in main function by imposing try catch block on derive class object p then rogramme is not terminated.
#include <iostream>
#include <memory>
using namespace std;
class A
{
int *memory;
public:
A()
{
cout<<"calling constructor class A\n";
memory= new int [100000000000000];
}
void show()
{
cout<<"show A\n";
}
~A()
{
cout<<"calling destructor class A\n";
}
};
class B : public A
{
public:
B()
try :A() {
cout<<"calling B's constructor\n";
}
catch(...)
{
cout << "exception occurred\n";
}
~B()
{
cout<<"calling B's destructor\n";
}
};
int main()
{
B obj;
obj.show();
return 1;
}