S
Senthilvel
Hi,
The automatic variables declared in the try bock will be destroyed when an
exception is thrown
due to stack unwinding.
So i expected the following code to call the destructor of B but it never
happened.
Am i wrong somewhere or is it my VC++6 compiler giving me problems????
Thanks and Best Regards,
Senthilvel.
#include <iostream>
using namespace std;
struct A
{
A() { cout<< "A's constructor"<<endl;}
~A() { cout<< "A's destructor"<<endl;}
};
struct B
{
B() { cout<< "B's constructor"<<endl;}
~B() { cout<< "B's destructor"<<endl;}
};
void f()
{
A a;
try
{
B b;
int i = 0;
i /= i; // I just wanted to throw some exception
}
catch(out_of_range& err) // I don't want the exception to be caught
here...Lemme catch it in main..
{
err;
}
}
int main()
{
try
{
f();
}
catch(...)
{
cout<<"Exception caught in main!!!"<<endl;
}
return 0;
}
the oputput i get is
A's constructor
B's constructor
A's destructor
Exception caught in main!!!
The automatic variables declared in the try bock will be destroyed when an
exception is thrown
due to stack unwinding.
So i expected the following code to call the destructor of B but it never
happened.
Am i wrong somewhere or is it my VC++6 compiler giving me problems????
Thanks and Best Regards,
Senthilvel.
#include <iostream>
using namespace std;
struct A
{
A() { cout<< "A's constructor"<<endl;}
~A() { cout<< "A's destructor"<<endl;}
};
struct B
{
B() { cout<< "B's constructor"<<endl;}
~B() { cout<< "B's destructor"<<endl;}
};
void f()
{
A a;
try
{
B b;
int i = 0;
i /= i; // I just wanted to throw some exception
}
catch(out_of_range& err) // I don't want the exception to be caught
here...Lemme catch it in main..
{
err;
}
}
int main()
{
try
{
f();
}
catch(...)
{
cout<<"Exception caught in main!!!"<<endl;
}
return 0;
}
the oputput i get is
A's constructor
B's constructor
A's destructor
Exception caught in main!!!