让:
void foo( void )
{
throw std::exception( "" );
}
void bar( void )
{
try
{
foo():
}
catch( ... )
{
throw;
}
}
void baz( void )
{
try
{
bar();
}
catch( ... )
{
}
}
baz()捕获了什么? std :: exception还是别的什么?
感谢您的帮助!
答案 0 :(得分:3)
它捕获std::exception
引发的foo
。 (至少,如果有可能首先抛出std::exception
,那么。throw;
没有操作数会重新抛出当前正在处理的异常对象。
答案 1 :(得分:1)
是的,在这种情况下,baz
会抓住std::exception
。
但是在抛出std::exception
时要小心,因为它应该用作异常的基类。 C ++标准(第18.8.1节)指定std::exception
只有一个默认构造函数和一个复制构造函数,因此你不能将消息放入其中。
请考虑使用std::runtime_error
。