Rule Definition
If a program throws an unhandled exception it terminates in an implementation-defined manner. In particular, it is implementation-defined whether the call stack is unwound, before termination, so the destructors of any automatic objects may or may not be executed. By enforcing the provision of a “last-ditch catch-all”, the developer can ensure that the program terminates in a consistent manner. This rule’s objective is to ensure that exceptions that were not expected are also caught.
Remediation
Add a catchall handler in the main function
Violation Code Sample
int32_t main( )
{
try
{
// program code
}
catch
{
//handle runtime exception
}
return 0;
}
Fixed Code Sample
int32_t main( )
{
try
{
// program code
}
catch ( ... ) // Catch-all handler
{
// Handle unexpected exceptions
}
return 0;
}
Reference
MISRA C++ 2008, 15-3-2: There should be at least one exception handler to catch all otherwise unhandled exceptions
AUTOSAR C++ 2014, Rule A15-3-3: There shall be at least one exception handler to catch all otherwise unhandled exceptions.
Related Technologies
Technical Criterion
PCI-DSS4-Requirement-6.2.4 - Software engineering techniques or other methods are defined and in use by software development personnel to prevent or mitigate common software attacks and related vulnerabilities
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.