Skip to main content

IAR Embedded Workbench for RISC-V 3.40

MISRAC++2008-15-5-1 (C++ only)

In this section:
Synopsis

(Required) A class destructor shall not exit with an exception.

Enabled by default

Yes

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

An exception is thrown, or might be thrown, in a class destructor. This check is identical to COP-dtor-throw.

Coding standards
CERT ERR33-CPP

Destructors must not throw exceptions

Code examples

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

class E{};

class C {
  ~C() {
    if (!p){
      throw E();  //may throw an exception here
    }
  }
  int* p;
};

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

void do_something();

class C {
  ~C() {  //OK
    if (!p){
      do_something();
    }
  }
  int* p;
};