THROW-main (C++ only)
In this section:
Synopsis
No default exception handler for main.
Enabled by default
No
Severity/Certainty
Medium/High

Full description
A main does not have a default exception handler that will catch exceptions. Without this, an unhandled exception might lead to termination in an implementation-defined manner. This check is identical to MISRAC++2008-15-3-2, MISRAC++2023-18.3.1.
Coding standards
- MISRA C++ 2008 15-3-2
(Advisory) There should be at least one exception handler to catch all otherwise unhandled exceptions
- MISRA C++ 2023 18.3.1
(Advisory) There should be at least one exception handler to catch all otherwise unhandled exceptions
Code examples
The following code example fails the check and will give a warning:
int main()
{
try
{
throw (42);
}
catch (int i)
{
if (i > 10)
{
throw;
}
}
return 1;
}
The following code example passes the check and will not give a warning about this issue:
int main()
{
try
{
throw;
}
catch (...) {}
// spacer
try {}
catch (int i) {}
catch (...) {}
return 0;
}