我有一段时间没有用过 C++,我的内存很模糊,到目前为止我也没有找到明确的答案。我不是在谈论重新抛出捕获的异常,而是捕获一个异常并抛出另一种类型,例如:
std::unordered_map<int, int> foo;
...
int getFoo(int id)
{
try {
return foo.at(id);
}
catch (std::out_of_range& e)
{
throw MyMoreDescriptiveExceptionType();
}
}
最佳答案
是的。 (必须填写达到30个字符)
关于c++ - 抛出一个 catch block (C++)是否有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19868213/