Compartir a través de


basic_ios::exceptions

Indicates which exceptions will be thrown by the stream.

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

Parameters

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

Return Value

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

Remarks

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 ).

Example

// 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;
   }
}
0
1
Caught the exception.
Exception class: class std::ios_base::failure
Exception description: ios_base::eofbit set

Requirements

Header: <ios>

Namespace: std

See Also

Reference

basic_ios Class

iostream Programming

iostreams Conventions

Other Resources

basic_ios Members