Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#FFcccc
langcpp

int main(int argc, char** argv) {
  Object object; // might not get destroyed if exception thrown
  // do useful work
  return 0;
}

...

Code Block
bgColor#ccccff
langcpp

int main(int argc, char** argv) {
  Object object;
  int exit_status = EXIT_SUCCESS;

  try {
    // do useful work
  } catch (...) {
    exit_status = EXIT_FAILURE;
  }

  return exit_status; // object gets destroyed here
}

...

Code Block
bgColor#ccccff
langcpp

int main(int argc, char** argv) {
  try {
    Object object;
    // do useful work
    return 0; // object gets destroyed here
  } catch (...) {
    exit(EXIT_FAILURE);  
  }
}

...

Code Block
bgColor#FFcccc
langcpp

using namespace std;
class exception1 : public exception {};
class exception2 : public exception {};

void f(void) throw( exception1) {
  // ...
  throw (exception2());
}

int main() {
  try {
    f();
    return 0;
  } catch (...) {
    cerr << "F called" << endl;
  }
  return EXIT_FAILURE;
}

...

Code Block
bgColor#ccccff
langcpp

using namespace std;
class exception1 : public exception {};
class exception2 : public exception {};

void f(void) throw( exception1) {
  // ...
  throw (exception1());
}

int main() {
  try {
    f();
    return 0;
  } catch (...) {
    cerr << "F called" << endl;
  }
  return EXIT_FAILURE;
}

...

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

ERR30-CPP

low

unlikely

low

P3

L3

Automated Detection

Tool

Version

Checker

Description

 PRQA QA-C++

 
Include Page
PRQA QA-C++_v
PRQA QA-C++_v

4037,4038,4636,4637

 

Other Languages

This rule appears in the Java Secure Coding Standard as EXC08-J. Try to gracefully recover from system errors.

...

ERR14-CPP. Do not allow an exception class's copy constructor to throw exceptions      12012. Exceptions and Error Handling (ERR)      ERR31-CPP. Don't redefine errno