std::exception::exception
cppreference.netから
exception() throw();
|
(1) | (C++11まで) |
exception() noexcept;
|
(C++11から) (constexpr C++26から) |
|
exception( const exception& other ) throw();
|
(2) | (C++11まで) |
exception( const exception& other ) noexcept;
|
(C++11から) (constexpr C++26から) |
|
新しい例外オブジェクトを構築します。
1) デフォルトコンストラクタ。what() は実装定義の文字列を返します。
2) コピーコンストラクタ。
other の内容で初期化します。もし *this と other の両方が動的な型 std::exception を持つ場合、std::strcmp(what(), other.what()) == 0。パラメータ
| other | - | コンテンツを割り当てるための別の例外 |
注記
std::exceptionのコピーは例外をスローすることが許可されていないため、派生クラス(例えばstd::runtime_error)がユーザー定義の診断メッセージを管理する必要がある場合、通常はコピーオンライト文字列として実装されます。
Microsoftの実装には、文字列を受け取る非標準のコンストラクタが含まれており、意味のあるエラーメッセージと共にインスタンスを直接スローすることが可能です。最も近い標準の同等物は std::runtime_error または std::logic_error です。
不具合報告
以下の動作変更の欠陥報告書は、以前に公開されたC++規格に対して遡及的に適用されました。
| DR | 適用対象 | 公開時の動作 | 正しい動作 |
|---|---|---|---|
| LWG 471 | C++98 | 例外のコピーの what() に関する要件がない | 追加された |