名前空間
変種
操作

std::bad_exception

From cppreference.com
< cpp‎ | error
 
 
ユーティリティライブラリ
言語サポート
型のサポート (基本型、RTTI)
ライブラリ機能検査マクロ (C++20)
プログラムユーティリティ
可変引数関数
コルーチンサポート (C++20)
契約サポート (C++26)
三方比較
(C++20)
(C++20)(C++20)(C++20)  
(C++20)(C++20)(C++20)

汎用ユーティリティ
関係演算子 (C++20で非推奨)
 
 
 
ヘッダー <exception> で定義
class bad_exception;

std::bad_exception は、C++ランタイムが以下の状況でスローする例外の型です。

  • もし std::exception_ptr がキャッチされた例外のコピーを格納しており、そして std::current_exception によってキャッチされた例外オブジェクトのコピーコンストラクタが例外をスローした場合、キャプチャされた例外は std::bad_exception のインスタンスになります。
(C++11以降)
  • もし動的な例外仕様 (dynamic exception specification) が違反され、かつ std::unexpected が例外仕様を依然として違反する例外をスローまたは再スローし、しかしその例外仕様が std::bad_exception を許可している場合、std::bad_exception がスローされます。
(C++17まで)
cpp/error/exceptionstd-bad exception-inheritance.svg

継承図

std::bad_exception のすべてのメンバ関数は constexpr です。

(C++26以降)

目次

[編集] メンバ関数

bad_exception オブジェクトを構築します。
(public member function)
オブジェクトをコピーします。
(public member function)
[virtual]
説明文字列を返す
(仮想 public メンバ関数)

std::exception から継承

メンバ関数

例外オブジェクトを破棄する
(std::exception の仮想 public メンバー関数) [編集]
[virtual]
説明文字列を返す
(std::exception の仮想 public メンバー関数) [編集]

[編集] 注記

機能テストマクロ 規格 機能
__cpp_lib_constexpr_exceptions 202411L (C++26) constexpr for exception types

[編集]

C++14 以前のモードでのみコンパイルされます(警告が発行される場合があります)。

#include <exception>
#include <iostream>
#include <stdexcept>
 
void my_unexp()
{
    throw;
}
 
void test()
    throw(std::bad_exception) // Dynamic exception specifications
                              // are deprecated in C++11
{
    throw std::runtime_error("test");
}
 
int main()
{
    std::set_unexpected(my_unexp); // Deprecated in C++11, removed in C++17
 
    try
    {
        test();
    }
    catch (const std::bad_exception& e)
    {
        std::cerr << "Caught " << e.what() << '\n';
    }
}

実行結果の例

Caught std::bad_exception
English 日本語 中文(简体) 中文(繁體)