Reputation: 8315
Let :
void foo( void )
{
throw std::exception( "" );
}
void bar( void )
{
try
{
foo():
}
catch( ... )
{
throw;
}
}
void baz( void )
{
try
{
bar();
}
catch( ... )
{
}
}
What does baz() catch ? An std::exception or something else ?
Thanks for your help !
Upvotes: 2
Views: 117
Reputation: 254471
It catches the same std::exception
that was thrown by foo
. (At least, it would, if it were possible to throw std::exception
like that in the first place.) throw;
with no operand rethrows the exception object that's currently being handled.
Upvotes: 3
Reputation: 2057
Yes, baz
catches std::exception
in this case.
But be careful when throwing std::exception
because it should be used as a base class of exceptions. C++ Standard (Paragraph 18.8.1) specifies that std::exception
only has a default constructor and a copy constructor, so you cannot put message into it.
Consider using std::runtime_error
instead.
Upvotes: 1