class A{
public:
A() { throw string("exception A"); };
};
class B{
A a;
public:
B() try : a() {} catch(string& s) { cout << &s << " " << s << endl; };
};
int main(){
try{
B b;
}catch(string& s){
cout << &s << " " << s << endl;
}
return 0;
}
The output is:
0x32c88 exception A
0x32c88 exception A
Since the exception was already caught in the constructor of B
, why it still occur in the main function?