std::ios_base::failure
提供: cppreference.com
ヘッダ <ios> で定義
|
||
class failure; |
||
クラス std::ios_base::failure は入出力ライブラリで失敗したときにその関数によって投げられる例外オブジェクトを定義します。
std::ios_base::failure は std::ios_base のメンバクラスとして定義されるかもしれませんし、同等な機能を持つ別のクラスの同義語 (typedef) として定義されるかもしれません。 (C++17以上)
(C++11未満) | |
(C++11以上) |
目次 |
[編集] メンバ関数
コンストラクタ |
例外オブジェクトを構築します (パブリックメンバ関数) |
std::ios_base::failure::failure
explicit failure( const std::string& message ); |
(C++11未満) | |
explicit failure( const std::string& message, const std::error_code& ec = std::io_errc::stream ); |
(C++11以上) | |
explicit failure( const char* message, const std::error_code& ec = std::io_errc::stream ); |
(C++11以上) | |
後に what() を使用して取得できる説明文字列として message
を使用して例外オブジェクトを構築します。
引数
message | - | 説明文字列 |
std::system_error から継承
メンバ関数
エラーコードを返します ( std::system_error のパブリックメンバ関数)
| |
[仮想] |
説明文字列を返します ( std::system_error の仮想パブリックメンバ関数)
|
std::runtime_error から継承
std::exception から継承
メンバ関数
[仮想] |
例外オブジェクトを破棄します ( std::exception の仮想パブリックメンバ関数)
|
[仮想] |
説明文字列を返します ( std::exception の仮想パブリックメンバ関数)
|
[編集] 例
Run this code
#include <iostream> #include <fstream> int main() { std::ifstream f("doesn't exist"); try { f.exceptions(f.failbit); } catch (const std::ios_base::failure& e) { std::cout << "Caught an ios_base::failure.\n" << "Explanatory string: " << e.what() << '\n' << "Error code: " << e.code() << '\n'; } }
出力:
Caught an ios_base::failure. Explanatory string: ios_base::clear: unspecified iostream_category error Error code: iostream:1
[編集] 関連項目
(C++11) |
iostream のエラーコード (列挙) |