다음을 통해 공유


basic_ios::exceptions

Indicates which exceptions will be thrown by the stream.

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

매개 변수

  • _Newexcept
    The flags that you want to throw an exception.

반환 값

The flags that are currently specified to thrown an exception for the stream.

설명

The first member function returns the stored exception mask. The second member function stores _Except in the exception mask and returns its previous stored value. Note that storing a new exception mask can throw an exception just like the call clear( 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;
   }
}
  

요구 사항

Header: <ios>

네임스페이스: std

참고 항목

참조

basic_ios 클래스

iostream 프로그래밍

iostreams 규칙