Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.


Indicates which exceptions will be thrown by the stream.

iostate exceptions( ) const; 
void exceptions( 
   iostate _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;
      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;


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

Header: <ios>

Community Additions

© 2015 Microsoft