noexcept
is a tool with a specific purpose to allow 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 std::vector
move its elements if your move constructors are noexcept
.
Tagging every function with noexcept
is probably not a good idea. The overuse and purposeless use of a tool does not bring benefits, on the contrary. The noexcept
specifier works like a contract: it adds it to functions that you are absolutely sure will not throw (reads throw
) an exception, and that will never be changed to possibly launchable, or if you definitely want It is assumed that std::terminate
is called if an exception occurs.
But that does not mean adding noexcept
to any and all functions arbitrarily.
However, you can 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 full of throw
s.