【发布时间】:2012-07-20 07:43:34
【问题描述】:
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的构造函数中被捕获了,为什么它还在main函数中出现?
【问题讨论】:
标签: c++ exception constructor