When I have a method that calls a set of methods that provide a reliable guarantee, I often have the problem of rolling back changes to also have a strong guarantee method. Let an example be used:
void MacroMethod() throw(...)
{
int i = 0;
try
{
for(i = 0; i < 100; ++i)
SetMethod(i);
}
catch(const std::exception& _e)
{
for(int j = i; j >= 0; --j)
UnsetMethod(j);
throw;
}
}
void SetMethod(int i) throw(...)
{
}
void UnsetMethod() throw(...)
{
}
Obviously, UnsetMethod could give up. In this case, my MacroMathod () offers only a basic guarantee. However, I did everything I could to offer a reliable guarantee, but I cannot be absolutely sure that my UnsetMethod () will not throw. Here are my questions:
- Should I even try to offer a strong guarantee in this case?
- Should I document my MacroMethod () as having a basic or strong guarantee? Even if it is very unlikely that UnsetMethod will throw?
- ?
- , , UnsetMethod() , , catch?
!