命名空间
变体
操作

std::basic_ios<CharT,Traits>::exceptions

来自 cppreference.cn
< cpp‎ | io‎ | basic ios
 
 
 
 
std::ios_base::iostate exceptions() const;
(1)
void exceptions( std::ios_base::iostate except );
(2)

获取和设置流的异常掩码。异常掩码决定了哪些错误状态会触发 failure 类型的异常。

1) 返回异常掩码。
2) 将异常掩码设置为 except。如果调用时流具有异常掩码覆盖的错误状态,则会立即触发异常。

目录

[编辑] 参数

except - 异常掩码

[编辑] 返回值

1) 当前的异常掩码。
2) (无)

[编辑] 注解

[编辑] 示例

#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