std::basic_ios<CharT,Traits>::exceptions
提供: cppreference.com
<tbody>
</tbody>
std::ios_base::iostate exceptions() const; |
(1) | |
void exceptions( std::ios_base::iostate except ); |
(2) | |
ストリームの例外マスクを取得および設定します。 例外マスクは、どのエラー状態の発生時にストリームが failure 型の例外を投げるかを決定します。
1) 例外マスクを返します。
2) 例外マスクを
except に設定します。引数
| except | - | 例外マスク |
戻り値
1) 現在の例外マスク。
2) (なし)
ノート
| This section is incomplete Reason: discuss LWG2349 and link from ios_base::clear, and from (un)formatted(i/o)utputfunction requirement pages (or perhaps the behavior should be fully elaborated on the requirement pages and linked from here). See also stackoverflow.com/a/35089910 |
例
Run this code
#include <iostream>
#include <fstream>
int main()
{
int ivalue;
try {
std::ifstream in("in.txt");
in.exceptions(std::ifstream::failbit);
in >> ivalue;
} catch (std::ios_base::failure& fail) {
// handle exception here
}
}