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.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) throw(std::exception);               // ok: this is an exception specification,
                                                                 // not a throw statement.
void f_throw_stmt(void){
  if (has_logic_error()){
    throw std::logic_error("Logic error."); // 'Use of throw' warning issued here.
  }
}

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

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