basic_ios::exceptions

指示哪些异常由引发。流

iostate exceptions( ) const;
void exceptions(
    iostate _Newexcept
);
void exceptions(
    io_state _Newexcept
);

参数

  • _Newexcept
    标志要引发异常。

返回值

当前指定引发流的异常的标记。

备注

第一个成员函数返回存储异常的掩码。 在异常蒙板和返回的第二个成员函数存储 _Except 其以前存储的值。 注意存储新异常的掩码,可以引发异常与调用 清除( rdstate )。

示例

// basic_ios_exceptions.cpp
// compile with: /EHsc /GR
#include <iostream>

int main( )
{
   using namespace std;

   cout << cout.exceptions( ) << endl;
   cout.exceptions( ios::eofbit );
   cout << cout.exceptions( ) << endl;
   try 
   {
      cout.clear( ios::eofbit );   // Force eofbit on
   }
   catch ( exception &e ) 
   {
      cout.clear( );
      cout << "Caught the exception." << endl;
      cout << "Exception class: " << typeid(e).name()  << endl;
      cout << "Exception description: " << e.what() << endl;
   }
}
  

要求

页眉: <ios>

命名空间: std

请参见

参考

basic_ios 类

iostream 编程

iostreams 约定