fel*_*415 6 c++ exception-handling exception
我知道处理这两个捕获的区别,但是椭圆需要捕获std :: exception catch无法捕获的内容?
例如:
try
{
throw std::runtime("runtime error!");
}
catch(const std::exception& e)
{
std::cout << "Exception: " << e;
}
catch(...)
{
std::cout << "How did I get here?";
throw;
}
Run Code Online (Sandbox Code Playgroud)
我已经看到了将这两者结合使用的代码示例,但我没有看到你同时做这两件事的原因.
catch(const std::exception& e)
Run Code Online (Sandbox Code Playgroud)
只会捕获 std 异常。
catch(...)
Run Code Online (Sandbox Code Playgroud)
之后会抓住一切。
您可以处理整数和其他类型(http://www.cplusplus.com/doc/tutorial/exceptions/)
例如:
catch(int e)
Run Code Online (Sandbox Code Playgroud)