Dynamic exception-specification shall not be used
Dynamic exception-specification shall not be used.
Dynamic exception specification is the method of specifying how a function behaves in
case of an exception by using a throw(<list of
exceptions>) statement in the function declaration. Using dynamic
exception specification has these issues:
Performance cost: Because dynamic exception specifications are checked at runtime, it adds to overhead and might reduce code performance.
Not suitable for generic programming: Because the precise type of exceptions
raised by function or class templates are generally not known beforehand, it can be
difficult to use throw statements in generic code.
For these reasons, avoid the throw(<list of
exceptions>) statement to specify exceptions. Use the
noexcept keyword instead. Because the noexcept
statements are checked at compile time, it is suitable for generic programming and generally
provides better performance than throw statements. The C++11 standard
specifies that dynamic exception specification will be removed from C++ in the
future.
When a throw(<list of exceptions>) statement
is used in a function declaration, Polyspace® flags the throw statement. Polyspace does not flag throw statements that are used for raising an
exception.
If you expect a rule violation but do not see it, refer to the documentation for Polyspace Bug Finder™ or Polyspace Bug Finder Server™.
| Group: Exception handling |
| Category: Required, Automated |