抛出catch块(C++)是否有效?

Mer*_*rad 1 c++ exception-handling exception

我有一段时间没有做过C++而且我的记忆很模糊,到目前为止我找不到确定的答案.我不是在讨论重新抛出捕获的异常,而是捕获一个异常并抛出不同的类型,例如:

std::unordered_map<int, int> foo;
...
int getFoo(int id)
{
  try {
    return foo.at(id);
  }
  catch (std::out_of_range& e)
  {
    throw MyMoreDescriptiveExceptionType();
  }
}
Run Code Online (Sandbox Code Playgroud)

Pet*_*ker 7

是.(必须填写达到30个字符)

  • 就个人而言,是你回答的后半部分为我做的。+1 (2认同)