Skip to main content

IAR Embedded Workbench for RX 5.20

THROW-unhandled (C++ only)

In this section:
Synopsis

There are calls to functions explicitly declared to throw an exception type that is not handled (or declared as thrown) by the caller.

Enabled by default

Yes

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

There are calls to functions explicitly declared to throw an exception type that is not handled (or declared as thrown) by the caller. If an application 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 might not be invoked. If an exception is thrown as an object of a derived class, a compatible type might be either the derived class or any of its bases. Make sure that the application catches all exceptions it is expected to throw. This check is identical to MISRAC++2008-15-3-4.

Coding standards
MISRA C++ 2008 15-3-4

(Required) Each exception explicitly thrown in the code shall have a handler of a compatible type in all call paths that could lead to that point.

Code examples

The following code example fails the check and will give a warning:

class E1{};

#ifndef __cpp_noexcept_function_type
void foo(int i) throw (E1) {
#else
void foo(int i) {
#endif
  if (i<0)
    throw E1();
}

int bar() {
  foo(-3);
}

The following code example passes the check and will not give a warning about this issue:

class E1{};

#ifndef __cpp_noexcept_function_type
void foo(int i) throw (E1) {
#else
void foo(int i) {
#endif
  if (i<0)
    throw E1();
}

int bar() {
  try {
    foo(-3);
  }
  catch (E1){
  }
}