CXX.EMPTY.CATCH

Empty catch clause silently discards exception

This checker is applicable only to the modern engine.

CXX.EMPTY.CATCH detects exception handlers with empty bodies. It reports both typed catch blocks and catch-all handlers that catch an exception but perform no action. Empty catch handlers silently suppress exceptions without handling, logging, or propagating them, which can hide errors, make failures difficult to diagnose, and complicate debugging and maintenance.

Mitigation and prevention

Never leave a catch handler with no body. At minimum, add a statement that makes the decision to ignore the exception explicit and auditable, such as a logging call, an assertion, or an explicit no-op marker function, rather than relying on a comment, which the compiler (and this checker) cannot see. If the exception should propagate further, rethrow it (throw;) instead of swallowing it.

Vulnerable code example 1: empty typed catch

Copy
void nonCompliant() {
  try {
    mightThrow();
  } catch (const std::exception &e) {   // CXX.EMPTY.CATCH — exception silently discarded
  }
}

Vulnerable code example 2 (empty catch-all)

Copy
void alsoNonCompliant() {
  try {
    mightThrow();
  } catch (...) {                       // CXX.EMPTY.CATCH
  }
}

Vulnerable code example 3: comment-only body (still fires; documented limitation)

Copy
void commentOnly() {
  try {
    mightThrow();
  } catch (...) {
    // intentionally ignored, logged elsewhere   -- CXX.EMPTY.CATCH still fires: comments
  }                                              -- are invisible to the AST
}

Fixed code example 1: handle or log

Copy
void compliant() {
  try {
    mightThrow();
  } catch (const std::exception &e) {
    log(e.what());
  }
}

Fixed code example 2: destructor swallow (exempt, no code change needed)

Copy
class Resource {
public:
  ~Resource() {
    try {
      release();
    } catch (...) {                     // exempt: nearest enclosing function is a destructor
    }
  }
};

Related checkers