noexcept
is a tool with a specific purpose of allowing certain optimizations, which would not be possible if exceptions had to be taken into account.
The first optimization that comes into my head right now is the std::vector
move your elements if your move constructors are noexcept
.
Mark every function with noexcept
probably not a good idea. Excessive and purposeless use of a tool does not bring benefits, on the contrary. The specifier noexcept
works like a contract: adds it in functions that is absolutely sure that it will not launch (reads throw
) an exception, and that will never be exchanged for possibly playable, or if definitely desired std::terminate
is called if an exception occurs.
But that doesn’t mean adding noexcept
in any function arbitrarily.
However, it is possible to disable C++ exceptions in compilers GCC, Clang and MSVC, rendering the use of noexcept
redundant. It is necessary, however, to recompile the standard library to use it without exceptions, or simply abandon it, because it is filled with throw
s.