std::basic_ios<CharT,Traits>::exceptions
From cppreference.com
| std::ios_base::iostate exceptions() const; |
(1) | |
| void exceptions( std::ios_base::iostate except ); |
(2) | |
ストリームの例外マスクを取得および設定します。例外マスクは、どのエラー状態が failure 型の例外をトリガーするかを決定します。
1) 例外マスクを返します。
2) 例外マスクを except に設定します。呼び出し時に、例外マスクでカバーされるエラー状態がストリームに存在する場合、例外が直ちにトリガーされます。
目次 |
[編集] パラメータ
| except | - | 例外マスク |
[編集] 戻り値
1) 現在の例外マスク。
2) (なし)
[編集] 注記
| このセクションは未完成です 理由: LWG2349 を議論し、ios_base::clear および (un)formatted(i/o)utputfunction 要件ページからリンクすること、または動作を要件ページで完全に説明し、ここからリンクすること。また、stackoverflow.com/a/35089910 も参照。 |
[編集] 例
このコードを実行
#include <fstream> #include <iostream> int main() { int ivalue; try { std::ifstream in("in.txt"); in.exceptions(std::ifstream::failbit); // may throw in >> ivalue; // may throw } catch (const std::ios_base::failure& fail) { // handle exception here std::cout << fail.what() << '\n'; } }
実行結果の例
basic_ios::clear: iostream error