Namespaces
Variants

std::exception:: exception

From cppreference.net
Utilities library
(1)
exception ( ) throw ( ) ;
(C++11まで)
exception ( ) noexcept ;
(C++11から)
(constexprはC++26から)
(2)
exception ( const exception & other ) throw ( ) ;
(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() に関する要件がない 追加された