std::basic_ios<CharT,Traits>::exceptions
来自 cppreference.cn
std::ios_base::iostate exceptions() const; |
(1) | |
void exceptions( std::ios_base::iostate except ); |
(2) | |
获取并设置流的异常掩码。异常掩码决定了哪些错误状态会触发 failure 类型的异常。
1) 返回异常掩码。
2) 将异常掩码设置为 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); // 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