小编use*_*213的帖子

重新抛出异常

为什么以下不能处理被重新抛出的异常?我尝试了所有的组合,但没有一个会在最后一次捕获中显示输出,所以我很困惑!

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)

c++ exception

14
推荐指数
2
解决办法
3万
查看次数

标签 统计

c++ ×1

exception ×1