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;
}
输出结果为:
0x32c88 exception A
0x32c88 exception A
既然异常已经在B
的构造函数中捕获,为什么它会在主函数中继续出现?