AUTOSAR C++14 Rule A15-4-1
Description
Rule Definition
Dynamic exception-specification shall not be used.
Rationale
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.
Polyspace Implementation
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.
Troubleshooting
If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Exception handling |
Category: Required, Automated |
Version History
Introduced in R2021a