Search code examples
c++exceptiontry-catchthrow

C++ Exception re-throwing and elipsis


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 !


Solution

  • 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.