为什么以下不能处理被重新抛出的异常?我尝试了所有的组合,但没有一个会在最后一次捕获中显示输出,所以我很困惑!
Derived D;
try {
throw D;
} catch ( const Derived &d) {
throw;
} catch (const Base &b) {
cout << "caught!" << endl;
}
Run Code Online (Sandbox Code Playgroud)
Derived D;
try {
throw D;
} catch ( const Derived d) {
throw;
} catch (const Base b) {
cout << "caught!" << endl;
}
Run Code Online (Sandbox Code Playgroud)
Derived D;
try {
throw D;
} catch ( const Derived d) {
throw;
} catch (const Base &b) {
cout << "caught!" << endl;
}
Run Code Online (Sandbox Code Playgroud)
Derived …Run Code Online (Sandbox Code Playgroud)