std::basic_ios<CharT,Traits>:: exceptions
From cppreference.net
|
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 以及(非)格式化输入/输出函数要求页面添加链接(或应将完整行为说明置于要求页面并在此处添加链接)。另请参阅 stackoverflow.com/a/35089910 |
示例
运行此代码
#include <fstream> #include <iostream> int main() { int ivalue; try { std::ifstream in("in.txt"); in.exceptions(std::ifstream::failbit); // 可能抛出异常 in >> ivalue; // 可能抛出异常 } catch (const std::ios_base::failure& fail) { // 在此处理异常 std::cout << fail.what() << '\n'; } }
可能的输出:
basic_ios::clear: iostream error