There are times where I want to be sure that some function call is executed before returning from an other function, or an integer is decremented.
For example consider this code:
void doSomething()
{
try
{
.....
.....
return;
.....
.....
.....
return;
......
} catch ( ... )
}
myvariable--;
}
I want to be sure that myvariable is always decremented, no mater if there is an exception, or a return call. Is there any build in object in C++ for this, or I should create my own class that accepts an std::function and executes it when the object gets out of scope at the object destructor?
For example, in C# there is the try..catch...finally block where in finally you can put any code you want to execute before returning from the function.