Is `catch(...) { throw; }` a bad practice?
- by ereOn
While I agree that catching ... without rethrowing is indeed wrong, I however believe that using constructs like this:
try
{
// Stuff
}
catch (...)
{
// Some cleanup
throw;
}
Is acceptable in cases where RAII is not applicable. (Please, don't ask... not everybody in my company likes object-oriented programming and RAII is often seen as "useless school stuff"...)
My coworkers says that you should always know what exceptions are to be thrown and that you can always use constructs like:
try
{
// Stuff
}
catch (exception_type1&)
{
// Some cleanup
throw;
}
catch (exception_type2&)
{
// Some cleanup
throw;
}
catch (exception_type3&)
{
// Some cleanup
throw;
}
Is there a well admited good practice regarding these situations?