AUTOSAR C++14 Rule A15-3-3
Main function and a task main function shall catch at least: base class exceptions from all third-party libraries used, std::exception and all otherwise unhandled exceptions
Since R2020b
Description
Rule Definition
Main function and a task main function shall catch at least: base class exceptions from all third-party libraries used, std::exception and all otherwise unhandled exceptions.
Rationale
During the execution of main()
or a task main function, different
exceptions can arise. For instance:
Explicitly raised exceptions of class
std::exception
Exceptions arising from the third-party libraries that you use
Unexpected exceptions
If any of these exceptions cannot be matched to a handler, the compiler
implicitly invokes the function std::terminate()
to abnormally terminate
program execution. Depending on the hardware and software that you use, this termination
process might invoke std::abort()
to abort program execution without
deleting the variables in the stack. Such an abnormal termination results in memory leaks
and security vulnerabilities.
Unhandled exceptions might cause an abnormal termination of the program execution,
leading to memory leaks and security vulnerabilities. To avoid these issues, execute the
operations of main()
or task main functions in a
try-catch
block. In the catch blocks:
Handle exceptions of type
std::exception
explicitly in appropriate catch blocks.Handle the base class of exceptions arising from third-party libraries.
Handle unexpected exceptions in a
catch(...)
block.
Polyspace Implementation
Polyspace® flags a
main()
function or a task main function if :Unhandled exceptions are raised in the function. For example, exceptions that are raised outside the
try-catch
block or in a catch block might remain unhandled.The function does not have a
try-catch
block.The function does not have catch blocks to explicitly handle
std::exception
type exceptions.The function does not have a catch-all or
catch(...)
blocks to handle unexpected exceptions.
Polyspace does not check if exceptions from third-party libraries are handled.
Polyspace flags a
main()
function or a task main function even if the unhandled exception might not be raised.
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, Partially automated |
Version History
Introduced in R2020b