You could use goto
for cleanups, something like:
void doSomething()
{
if (someCondition)
goto cleanUPA;
if (otherCondition)
goto cleanUPB;
if (oneMoreCondition)
goto cleanUPAll;
//All good then just
return;
cleanupUPB:
//respective cleanups
cleanupUPA:
//respective cleanups
cleanUPALL:
//respective cleanups
}
Possibly, could be implemented in a better way by using RAII in C++ but coming from a C background this is often where goto
is used, So if for any reason you cannot use RAII(I think hard to find such a scenario-possibly you are not using any smart pointers at all etc) then it can be a legitimate case.