名前空間
変種
操作

「cpp/error/bad exception」の版間の差分

提供: cppreference.com
< cpp‎ | error
(Translated from the English version using Google Translate)
 
()
 
(4人の利用者による、間の5版が非表示)
1行: 1行:
{{tr_note}}
 
 
{{cpp/title|bad_exception}}
 
{{cpp/title|bad_exception}}
{{cpp/error/navbar}}
+
{{cpp/error/navbar}}
{{ddcl list begin}}
+
{{begin}}
{{ddcl list header | exception}}
+
{{header | exception}}
{{ddcl list item |1=
+
{{|1=
 
class bad_exception;
 
class bad_exception;
 
}}
 
}}
{{ddcl list end}}
+
{{end}}
  
{{tr|{{tt|std::bad_exception}}次のような状況では、C + +ランタイムによってスローされた例外のタイプです|{{tt|std::bad_exception}} is the type of the exception thrown by the C++ runtime in the following situations:}}
+
{{tt|std::bad_exception}} C++
  
@1@ {{tr|[[cpp/language/except_spec|動的例外仕様]]が違反とされている場合は{{c|std::unexpected}}はスローや静止例外仕様に違反例外を再スローしますが、例外仕様はでき{{tt|std::bad_exception}}{{tt|std::bad_exception}}スローされます。.|If a [[cpp/language/except_spec|動的例外仕様]] is violated and {{c|std::unexpected}} throws or rethrows an exception that still violates the exception specification, but the exception specification allows {{tt|std::bad_exception}}{{tt|std::bad_exception}} is thrown.}}
+
{{
 
+
||
@2@ {{tr|{{c|std::exception_ptr}}がキャッチされた例外のコピーを格納し、{{c|current_exception}}によって捕捉された例外オブジェクトのコピーコンストラクタが例外をスローした場合、キャプチャされた例外が{{tt|std::bad_exception}}のインスタンスである場合.|If {{c|std::exception_ptr}} stores a copy of the caught exception and if the copy constructor of the exception object caught by {{c|current_exception}} throws an exception, the captured exception is an instance of {{tt|std::bad_exception}}.}}
+
{{|std::}} {{|std::}} {{tt|std::bad_exception}}
 +
 +
|
 +
[[cpp/language/except_spec|]]{{|std::unexpected}} {{tt|std::bad_exception}} {{tt|std::bad_exception}}
 +
}}
 +
{{}}
  
 
{{inheritance diagram/std-bad_exception}}
 
{{inheritance diagram/std-bad_exception}}
  
 
===メンバ関数===
 
===メンバ関数===
{{dcl list begin}}
+
{{begin}}
{{dcl list mem ctor | cpp/error/bad_exception/bad_exception |{{tr| {{tt|bad_exception}}オブジェクトを作成します| constructs the {{tt|bad_exception}} object}}}}
+
{{mem ctor | cpp/error/bad_exception/bad_exception | {{tt|bad_exception}} }}
{{dcl list mem fun | cpp/error/bad_exception/operator{{=}} |{{tr| オブジェクトをコピーします| copies the object}}}}
+
{{mem fun | cpp/error/bad_exception/operator{{=}} | オブジェクトをコピーします }}
{{dcl list mem vfun | cpp/error/bad_exception/what |{{tr| 説明文字列を返します| returns the explanatory string}}}}
+
{{mem vfun | cpp/error/bad_exception/what | 説明文字列を返します }}
{{dcl list end}}
+
{{end}}
  
 
{{cpp/error/exception/inherit}}
 
{{cpp/error/exception/inherit}}
51行: 55行:
 
     }
 
     }
 
}
 
}
 +
 
  | output=
 
  | output=
 
Caught std::bad_exception
 
Caught std::bad_exception
 
}}
 
}}
 +
 +

2020年4月25日 (土) 21:07時点における最新版

 
 
ユーティリティライブラリ
汎用ユーティリティ
日付と時間
関数オブジェクト
書式化ライブラリ (C++20)
(C++11)
関係演算子 (C++20で非推奨)
整数比較関数
(C++20)
スワップと型操作
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
一般的な語彙の型
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

初等文字列変換
(C++17)
(C++17)
 
エラー処理
例外処理
例外処理の失敗
bad_exception
(C++17未満)
(C++17未満)
(C++11)(C++17未満)
(C++17未満)
エラー番号
エラー番号
 
 
ヘッダ <exception> で定義
class bad_exception;

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/exceptionstd-bad exception-inheritance.svg
画像の詳細

継承図

目次

[編集] メンバ関数

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

std::exception から継承

メンバ関数

例外オブジェクトを破棄します
(std::exceptionの仮想パブリックメンバ関数) [edit]
[仮想]
説明文字列を返します
(std::exceptionの仮想パブリックメンバ関数) [edit]

[編集]

#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