Exception handling

Exception is not getting catched by catch block.

class abcd
{
public:
int a;
abcd(){cout<<"first"<<endl;
a = 5;
throw a;
}
~abcd(){cout<<"dfirst"<<endl;}
};
class abcde
{
public:
int b;
abcde(){cout<<"second"<<endl;
b= 9;}
~abcde(){
cout<<"dsecond"<<endl;
throw b;}
};
int main()
{
try
{
abcde BB;
abcd AA;
}
catch(int g)
{
cout<<"catch : "<<g<<endl;
}
return 0;
}

Mentioned code results in Debug error : R6010 -abord has been called.


How can i avoid this exception?
From now on, I shall refer to abcd as A and to abcde as B.

An A is constructed after a B. A::A() throws. In the process of handling this exception, the program must destruct both objects. During the process of destructing the B object, another exception is thrown. An exception that is thrown while another exception is being handled (i.e. after the throw statement has been executed but before the catch block is entered) causes the program to abort.

For this reason, don't throw in a destructor.
Last edited on
is there any way to handle this exception without removing throw statement from destructor ?
No.
Topic archived. No new replies allowed.