AUTOSAR C++14 Rule A15-3-4
Catch-all (ellipsis and std::exception) handlers shall be used only in (a) main, (b) task main functions, (c) in functions that are supposed to isolate independent components and (d) when calling third-party code that uses exceptions not according to AUTOSAR C++14 guidelines
Since R2020b
Description
Rule Definition
Catch-all (ellipsis and std::exception) handlers shall be used only in (a) main, (b) task main functions, (c) in functions that are supposed to isolate independent components and (d) when calling third-party code that uses exceptions not according to AUTOSAR C++14 guidelines.
Rationale
Catch-all handlers such as catch(std::exception)
or
catch(...)
blocks match many different types of exceptions. If you
handle an exception by using such a catch-all handler, you do not have detailed and specific
information about the raised exception. Such catch-all handlers cannot take meaningful
actions to handle the raised exceptions. These catch-all handlers are useful in processing
unexpected exceptions by raising the exceptions again or by properly exiting from the
application.
Because catch-all handlers are useful for specific purposes, it is inefficient to use them in every function. Use catch-all handlers in:
Main functions
Task main functions
Functions that call a third-party function that might be noncompliant with AUTOSAR C++14 guidelines
Functions that are designed to isolate independent components of your code
Polyspace Implementation
Polyspace® flags catch(std::exception)
and
catch(...)
blocks in a function if none of these are true:
The function is the
main()
function.The function is a task main function.
The function calls an external or third-party function that might exit with an exception.
Polyspace detects the main()
function. To specify a function as a
task main function, use these compilation options:
-entry-points <name>
-cyclic-tasks <name>
-interrupts <name>
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, Non-automated |
Version History
Introduced in R2020b