Daily bit(e) of C++ | Exception guarantees
Daily bit(e) of C++ #459, Exception guarantees in C++ code and the standard library.
When working with exceptions, there are three main levels of guarantees a function can provide when an exception is thrown.
Minimum guarantee: no invariants are violated, and no resources are leaked.
This is the minimum level for the standard library. Any codebase that has exceptions enabled should maintain at least this level.
Strong guarantee: the state will not be changed.
Operations are transactional; they either happen entirely without error or not at all.
While this is very nice to code against, strong exception guarantee support can be prohibitively expensive (or even impossible).
Nothrow guarantee: no exception will be thrown.
Suitable for trivial operations and building blocks of more complex functions that need to provide strong guarantees.
Note that this property should be consistent across all build configurations.