I understand that writing exception-safe code basically means taking into account what part of the code can throw exception, so that you can offer some guarantee about the behavior when an exception is indeed thrown. In particular, I take it that the best is to write code with a nothrow guarantee if the situation permits it.
The thing is, how do I know that my code cannot throw?
More precisely:
- Let's say that all functions that I use cannot throw (they have the
noexcept(true)
specifier, which I check with static_assert, and are implemented to ensure it). - Knowing that, can something still throw, like operations on basic types or function calls throw (not the function itself, but the function call)?
- Can an error occur without leading to an exception (for example, I heard that dividing an int by zero results in an error, but does not throw)