CodeQL documentation

Accidental rethrow

ID: cpp/rethrow-no-exception
Kind: problem
Security severity: 
Severity: warning
Precision: high
Tags:
   - reliability
   - correctness
   - exceptions
Query suites:
   - cpp-security-and-quality.qls

Click to see the query in the CodeQL repository

The C++ throw expression can take several forms. One form throws a new exception, whereas the other re-throws the current exception. In the latter case, if there is no current exception, then the program will be terminated. Presence of a re-throw outside of an exception handling context is often caused by the programmer not knowing what kind of exception to throw.

Recommendation

The throw expression should be changed to throw a particular type of exception.

Example

void bad() {
  /* ... */
  if(error_condition)
    throw;
}

void good() {
  /* ... */
  if(error_condition)
    throw std::exception("Something went wrong.");
}

References

  • © GitHub, Inc.
  • Terms
  • Privacy
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy