Skip to main content

IAR Embedded Workbench for RX 5.20

MISRAC++2008-15-3-2 (C++ only)

In this section:
Synopsis

(Advisory) There should be at least one exception handler to catch all otherwise unhandled exceptions

Enabled by default

No

Severity/Certainty

Medium/High

mediumhigh.png
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 THROW-main, MISRAC++2023-18.3.1.

Coding standards
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;
}