This documentation is archived and is not being maintained.

basic_ios::exceptions 

Indicates which exceptions will be thrown by the stream.


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

Parameters

_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;
   }
}

Output

0
1
Caught the exception.
Exception class: class std::ios_base::failure
Exception description: ios_base::eofbit set

Header: <ios>

Show: