JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.

If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.

If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.

CodeSonar® 9.2p0 CONFIDENTIAL CodeSecure Inc
C and C++


LANG.STRUCT.EXCP.THROW : Use of throw

Summary

The code contains a throw expression.

Properties

Class Name Use of throw
Significance style
Mnemonic LANG.STRUCT.EXCP.THROW
Categories
MisraC++2023 MisraC++2023:18.1.1 An exception object shall not have pointer type
  MisraC++2023:18.1.2 An empty throw shall only occur within the compound-statement of a catch handler
CWE CWE:397 Declaration of Throws for Generic Exception
CERT-CPP CERT-CPP:DCL57-CPP Do not let exceptions escape from destructors or deallocation functions
  CERT-CPP:ERR55-CPP Honor exception specifications
  CERT-CPP:ERR58-CPP Handle all exceptions thrown before main() begins executing
  CERT-CPP:ERR61-CPP Catch exceptions by lvalue reference
JSF++ JSF++:208 C++ exceptions shall not be used (i.e. throw, catch and try shall not be used.)
Availability Available for C++ only (not C).
Enabling Checks for this warning class are disabled by default. To enable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += allow class="Use of throw"

Example

#include <stdexcept>

bool has_logic_error(void);

void f_exception_spec(void) 

// This exception specification will cause an error in some compilers, such as C++17 compilers.
// We guard it with "#ifdef __CODESONAR__ ... #endif" so that it
// is preprocessed out by the native compiler (so the example can be compiled)
// but still observed by the CodeSonar analysis.
#ifdef __CODESONAR__
    throw(std::exception)                             // ok: this is an exception specification,
                                                      // not a throw statement.
#endif
    ;

void f_throw_stmt(void){
  if (has_logic_error()){
    throw std::logic_error("Logic error."); // 'Use of throw' warning issued here.
  }
}

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.

 

To report problems with this documentation, please visit https://support.codesecure.com/.