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

要旨

The code contains a throw expression.

プロパティ

クラス名 Use of throw
日本語クラス名 Use of throw
クラス分類 スタイル (style)
ニーモニック LANG.STRUCT.EXCP.THROW
カテゴリー
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.)
対応言語 C++ のみ利用可能です。 C は利用できません。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっています。チェックを有効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += allow class="Use of throw"

#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.
  }
}

関連のある設定ファイルパラメータ

設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。

 

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