std:: format_error
|
定義済みヘッダー
<format>
|
||
|
class
format_error
:
public
runtime_error
|
(C++20以降) | |
フォーマットライブラリでエラーを報告するためにスローされる例外オブジェクトの型を定義します。
std::format_errorのすべてのメンバー関数は
std::format_error
です:定数式の評価中に
std::format_error
オブジェクトを作成して使用することが可能です。
ただし、
|
(C++26以降) |
継承図
目次 |
メンバー関数
|
(constructor)
|
指定されたメッセージで新しい
format_error
オブジェクトを構築する
(public member function) |
|
operator=
|
format_error
オブジェクトを置き換える
(public member function) |
std::format_error:: format_error
|
format_error
(
const
std::
string
&
what_arg
)
;
|
(1) | (constexpr since C++26) |
|
format_error
(
const
char
*
what_arg
)
;
|
(2) | (constexpr since C++26) |
|
format_error
(
const
format_error
&
other
)
noexcept
;
|
(3) | (constexpr since C++26) |
std::format_error
である場合、
std::
strcmp
(
what
(
)
, other.
what
(
)
)
==
0
となります。コピーコンストラクタから例外が送出されることはありません。
パラメータ
| what_arg | - | 説明文字列 |
| other | - | コピーする別の例外オブジェクト |
例外
注記
std::format_error
のコピーは例外を送出することが許可されていないため、このメッセージは通常、別途割り当てられた参照カウント方式の文字列として内部に格納されます。これが
std::string&&
を受け取るコンストラクタが存在しない理由でもあります:いずれにせよ内容をコピーする必要があるためです。
派生した標準例外クラスは、公開されたコピーコンストラクタを持たなければなりません。元のオブジェクトとコピーされたオブジェクトの
what()
によって得られる説明文字列が同じである限り、暗黙的に定義することができます。
std::format_error:: operator=
|
format_error
&
operator
=
(
const
format_error
&
other
)
noexcept
;
|
(constexpr since C++26) | |
other
の内容を代入します。
*
this
と
other
の両方が動的型
std::format_error
を持つ場合、代入後は
std::
strcmp
(
what
(
)
, other.
what
(
)
)
==
0
となります。コピー代入演算子から例外が送出されることはありません。
パラメータ
| other | - | 代入する別の例外オブジェクト |
戻り値
* this
注記
派生した標準例外クラスは、公開されたコピー代入演算子を持たなければなりません。
what()
によって得られる説明文字列が元のオブジェクトとコピーされたオブジェクトで同じである限り、暗黙的に定義することができます。
std:: runtime_error から継承
std::exception から継承 std:: exception
メンバ関数
|
[virtual]
|
例外オブジェクトを破棄
(
std::exception
の仮想公開メンバ関数)
|
|
[virtual]
|
説明文字列を返す
(
std::exception
の仮想公開メンバ関数)
|
注記
| 機能テスト マクロ | 値 | 標準 | 機能 |
|---|---|---|---|
__cpp_lib_constexpr_exceptions
|
202502L
|
(C++26) | constexpr 例外型 |
例
#include <format> #include <print> #include <string_view> #include <utility> int main() { try { auto x13{37}; auto args{std::make_format_args(x13)}; std::ignore = std::vformat("{:()}", args); // throws } catch(const std::format_error& ex) { std::println("{}", ex.what()); } }
出力例:
format error: failed to parse format-spec