C ++ catch(std :: exception& e)与catch(...) [英] C++ catch(std::exception & e ) vs. catch(...)
本文介绍了C ++ catch(std :: exception& e)与catch(...)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道这两种捕获方法在处理上的区别,但是椭圆捕获std :: exception捕获方法不能捕获到什么东西?
I know the difference in handling of both of these catches, but what does it take for the ellipse to catch something the std::exception catch wouldn't 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;
}
我已经看到了将两者结合使用的代码示例,但是我还没有看到同时使用它们的原因。
I've seen examples of code that use both of these in conjunction, but I've not seen a reason you would do both.
推荐答案
catch(const std::exception& e)
仅捕获标准异常。
catch(...)
您可以处理整数和其他类型( http://www.cplusplus.com/doc/tutorial/exceptions/ )
You can handle integers and other types (http://www.cplusplus.com/doc/tutorial/exceptions/)
例如:
catch(int e)
这篇关于C ++ catch(std :: exception& e)与catch(...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文