std::bad_function_call
From cppreference.com
< cpp | utility | functional
| ヘッダ <functional> で定義 |
||
| class bad_function_call; |
||
std::bad_function_call は、関数ラッパーがターゲットを持たない場合に std::function::operator() によってスローされる例外の型です。
継承図
目次 |
[編集] メンバ関数
| (コンストラクタ) |
新しい bad_function_call オブジェクトを構築します(public member function) |
| operator= |
bad_function_call オブジェクトを置き換えます(public member function) |
| what |
説明文字列を返す (public member function) |
std::bad_function_call::bad_function_call
| bad_function_call() noexcept; |
(1) | (C++11以降) |
| bad_function_call( const bad_function_call& other ) noexcept; |
(2) | (C++11以降) |
実装定義のヌル終端バイト文字列を持つ新しい bad_function_call オブジェクトを構築します。この文字列は what() 経由でアクセス可能です。
1) デフォルトコンストラクタ。
2) コピーコンストラクタ。 *this と other が両方とも動的型
std::bad_function_call を持つ場合、 std::strcmp(what(), other.what()) == 0 です。パラメータ
| その他 | - | コピーする別の例外オブジェクト |
std::bad_function_call::operator=
| bad_function_call& operator=( const bad_function_call& other ) noexcept; |
(C++11以降) | |
other の内容を代入します。 *this と other が両方とも動的型 std::bad_function_call を持つ場合、代入後 std::strcmp(what(), other.what()) == 0 です。
パラメータ
| その他 | - | 割り当てる別の例外オブジェクト |
戻り値
*this
std::bad_function_call::what
virtual const char* what() const noexcept; |
(C++11以降) | |
説明文字列を返します。
戻り値
説明情報を含む、実装定義のヌル終端文字列へのポインタ。この文字列は std::wstring として変換および表示するのに適しています。このポインタは、それが取得された例外オブジェクトが破棄されるか、例外オブジェクトの非 const メンバー関数(例:コピー代入演算子)が呼び出されるまで、少なくとも有効であることが保証されます。
|
返された文字列は、定数評価中に通常のリテラルエンコーディングでエンコードされます。 |
(C++26以降) |
注釈
実装は what() をオーバーライドすることが許可されていますが、必須ではありません。
std::exception から継承
メンバ関数
| [virtual] |
例外オブジェクトを破棄する ( std::exception の仮想 public メンバー関数) |
| [virtual] |
説明文字列を返す ( std::exception の仮想 public メンバー関数) |
[編集] 例
このコードを実行
#include <functional> #include <iostream> int main() { std::function<int()> f = nullptr; try { f(); } catch (const std::bad_function_call& e) { std::cout << e.what() << '\n'; } }
実行結果の例
bad function call
[編集] 不具合報告
以下の動作変更を伴う欠陥報告が、以前に公開されたC++標準に遡って適用されました。
| DR | 適用対象 | 公開された動作 | 正しい動作 |
|---|---|---|---|
| LWG 2233 | C++11 | what() は常に同じ説明的な文字列を std::exception::what() として返していました。 |
それ自身の 説明文字列 |
[編集] 関連項目
| (C++11) |
コピー構築可能な任意の呼び出し可能オブジェクトをラップするコピー可能なラッパー (クラステンプレート) |