dimanche 6 décembre 2015

Do the same action at the end of the try block and all catch clocks in a try-catch statement

Is it a way to avoid code duplication (FinalAction function call in all catch blocks and in a try one)?

try
{
    // some actions
    FinalAction();
}
catch (const Exception1& ex1)
{
    ProcessException1(ex1);
    FinalAction();
}
catch (const Exception2& ex2)
{
    ProcessException2(ex2);
    FinalAction();
}
// ...
catch (const ExceptionN& exN)
{
    ProcessExceptionN(exN);
    FinalAction();
}
catch (...)
{
    ProcessUnknownException();
    FinalAction();
}

Aucun commentaire:

Enregistrer un commentaire