Exception specification is a language feature that can enable performance improvements, but on the other hand, when done incorrectly, it can abnormally terminate the program. The exception specification from C++03 which allowed you to indicate what types of exceptions a function could throw has been deprecated and replaced with the new C++11 noexcept
specification. This specification only allows you to indicate whether a function may throw or not. This recipe provides information about the modern exception specifications in C++, as well as guidelines on when to use it.
Use the following constructs to specify or query exception specifications:
- Use
nothrow
in a function declaration to indicate that the function is not throwing any exception:
void func_no_throw() noexcept { }
- Use
nothrow(expr)
in a function declaration, such as template metaprogramming, to indicate that the function may or may not throw an exception...