AutosarC++18_03-A15.4.1ΒΆ
Dynamic exception-specification shall not be used
Required inputs: IR
| Level | required |
|---|---|
| Target | implementation |
| Enforcement | automated |
Rationale
This feature was deprecated in the 2011 C++ Language Standard (See: DeprecatingException Specifications).
Main issues with dynamic exception specifications are:
- Run-time checking: Exception specifications are checked at runtime, so theprogram does not guarantee that all exceptions will be handled. The run-timefailure mode does not lend itself to recovery.
- Run-time overhead: Run-time checking requires the compiler to produceadditional code that hampers optimizations.
- Unusable in generic code: It is not possible to know what types of exceptionsmay be thrown from templates arguments operations, so a precise exceptionspecification cannot be written.
In place of dynamic exception-specification, use noexcept specification that allows todeclare whether a function throws or does not throw exceptions.
Note: std::unexpected_handler shall not be used.
Example
//% $Id: A15-4-1.cpp 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $
#include <stdexcept>
void F1() noexcept; // Compliant - note that noexcept is the same as
// noexcept(true)
void F2() throw(); // Non-compliant - dynamic exception-specification is
// deprecated
void F3() noexcept(false); // Compliant
void F4() throw(std::runtime_error); // Non-compliant - dynamic
// exception-specification is deprecated
void F5() throw(
...); // Non-compliant - dynamic exception-specification is deprecated
template <class T> void F6() noexcept(noexcept(T())); // Compliant
See Also
- C++ Core Guidelines [10]: E.12: Use noexcept when exiting a function because of a throw is impossible or unacceptable
- open-std.org [17]: open std Deprecating Exception Specifications
- mill22: A Pragmatic Look at Exception Specifications
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
throw_in_decl |
Dynamic exception-specification shall not be used. |
None |
False |
Options
This rule shares the following common options: confidence, exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
This rule has no individual options.