Use
C++ exceptions:
try
{
if (condition1_fails) throw 1;
...
if (condition2_fails) throw 2;
...
...
if (conditionN_fails) throw N;
PerformActionOnAllSuccess();
DoNormalCleanup();
}
catch (int condition)
{
printf("The condition %d fails!\n", condition);
DoFailedCleanup();
}
This way you have the overhead of the
C++ exeption handling mechanism, but you'll have more control on what to do: you can for instance
throw different exception types depending on the failed condition and
catch them on different
catch
blocks.