Bare rethrow used outside any catch block

ID

c.maintainability.rethrow_outside_catch

Severity

low

Remediation Complexity

trivial

Remediation Risk

medium

Remediation Effort

low

Resource

Error Handling

Language

C / C++

Description

A bare throw; re-raises the exception currently being handled, but there is no enclosing catch block here to hold one. Outside a handler this is undefined behavior — at best it calls std::terminate. Move this throw; inside the catch block it belongs to, or throw a new exception object if that is what was intended.

Rationale

A bare throw; re-raises the exception currently being handled, but there is no enclosing catch block here to hold one. Outside a handler this is undefined behavior — at best it calls std::terminate. Move this throw; inside the catch block it belongs to, or throw a new exception object if that is what was intended.

The following code illustrates the pattern detected by this rule:

void badBareThrow() {
  // FLAGGED: Bare rethrow used outside any catch block
  throw;
}

Remediation

Follow secure coding practices and review the references below for detailed remediation guidance.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved