T
thamizh.veriyan
I compiled this code on gcc 4.1.2 and the output I got seems to be a
bit weird.
Here is the code:
#include <iostream>
class A{
public:
A(){std::cout << "Constructor" << std::endl;}
~A(){std::cout << "Destructor" << std::endl;}
};
void display(){
A mystr;
throw mystr;
}
int main() {
try{
display();
}
catch(A str){
}
return 0;
}
The output happens to be:
Constructor
Destructor
Destructor
Destructor
I don't know if I am missing something. I checked all the references
that I have for exceptions. Looks like local objects get deleted
normally when exceptions are thrown. I cant seem to explain this
output. Would be grateful if the members here can help me with this.
Regards
Dana
bit weird.
Here is the code:
#include <iostream>
class A{
public:
A(){std::cout << "Constructor" << std::endl;}
~A(){std::cout << "Destructor" << std::endl;}
};
void display(){
A mystr;
throw mystr;
}
int main() {
try{
display();
}
catch(A str){
}
return 0;
}
The output happens to be:
Constructor
Destructor
Destructor
Destructor
I don't know if I am missing something. I checked all the references
that I have for exceptions. Looks like local objects get deleted
normally when exceptions are thrown. I cant seem to explain this
output. Would be grateful if the members here can help me with this.
Regards
Dana