共用方式為


basic_ios::exceptions

例外狀況會由資料流擲回的指示。

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

參數

  • _Newexcept
    旗標要擲回例外狀況。

傳回值

目前所指定的資料流的例外狀況的旗標。

備註

第 10% 成員函式傳回儲存的例外狀況遮罩。 在例外狀況遮罩和傳回的第二 + 成成員函式存放區 _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 慣例