◐ Shell
clean mode source ↗

std::bad_exception - cppreference.com

提供: cppreference.com

<tbody> </tbody>

std::bad_exception は以下の状況で C++ ランタイムによって投げられる例外の型です。

  • std::exception_ptr がキャッチされた例外のコピーを格納し、 std::current_exception によってキャッチされた例外オブジェクトのコピーコンストラクタが例外を投げた場合、キャプチャされる例外は std::bad_exception のインスタンスです。
(C++11以上)
  • 動的例外指定に違反し、 std::unexpected がその例外指定に違反する例外を投げたとき、その例外指定で std::bad_exception が許可されていれば、 std::bad_exception が投げられます。
(C++17未満)
cpp/error/exception

継承図

メンバ関数

bad_exception オブジェクトを構築します
(パブリックメンバ関数)
オブジェクトをコピーします
(パブリックメンバ関数)
説明文字列を返します
(仮想パブリックメンバ関数)

#include <iostream>
#include <exception>
#include <stdexcept>

void my_unexp() { throw; }

void test() throw(std::bad_exception)
{
    throw std::runtime_error("test");
}

int main()
{
    std::set_unexpected(my_unexp);
    try {
         test();
    } catch(const std::bad_exception& e)
    {
        std::cerr << "Caught " << e.what() << '\n';
    }
}

出力例:

Caught std::bad_exception