Consider the following code snippet:
void MyFun()
{
SetMe();
// more code
if (.. )
{
UnSetMe();
return;
}
// more codes
if ( .. )
{
UnSetMe();
return ;
}
// more code
UnSetMe();
}
As you can see, the function first calls SetMe() and then prior to terminating, calls UnSetMe(). Now its little bit cumbersome to add UnSetMe() at every places where the function has to exit and one may omit it by mistake in some places.
What would be an improved design to handle such situation.
You could call MyFun() from MyWrapperFun(), and then call UnsetMe() after: