S
Subra
Hi,
I am learning C++ and need export advice on the below program.
I have read it that whenever a exception is genrated and control
enteres the catch block it will call destructors for all the
successfuly completed constructors. But in the below case
i am doing :-
base *ptr=new base;
throw 44;
But the destructor for base is not called once it enters the catch
block. Please let me know why it is so and how to come out of it.
#include<iostream>
#include<exception>
using namespace std;
class base
{
public:
base() { cout<<"Constructor"<<endl; }
~base() { cout<<"Destructor"<<endl; }
};
int main()
{
try {
base *ptr=new base;
throw 44;
}catch(...) { // I am
expecting base destructor to be called here
cout<<" Inside catch"<<endl; // But it is not
}
}
I am learning C++ and need export advice on the below program.
I have read it that whenever a exception is genrated and control
enteres the catch block it will call destructors for all the
successfuly completed constructors. But in the below case
i am doing :-
base *ptr=new base;
throw 44;
But the destructor for base is not called once it enters the catch
block. Please let me know why it is so and how to come out of it.
#include<iostream>
#include<exception>
using namespace std;
class base
{
public:
base() { cout<<"Constructor"<<endl; }
~base() { cout<<"Destructor"<<endl; }
};
int main()
{
try {
base *ptr=new base;
throw 44;
}catch(...) { // I am
expecting base destructor to be called here
cout<<" Inside catch"<<endl; // But it is not
}
}