ios::exceptions
iostate exceptions ( ) const;
iostate exceptions ( iostate except );
ios
  cplusplus.com  

Get/set the exception mask.
  The first syntax returns the current exception mask for the stream.
  The second syntax sets a new exception mask and calls clear(rdstate()).
  The exception mask is a bitmask of stream state flags that represent the stream states that shall throw a standard exception when any of them is set. Possible bit values are:

  More than a single state flag bit can be combined. By default, standard stream objects have a goodbit exception mask.

Parameters.

except
An bitmask value of type ios_base::iostate formed by a combination of error state flag bits to be set (badbit, eofbit, failbit).

Return Value.
  A bitmask of type ios_base::iostate representing the existing exception mask before the call to this member function.

Example.

// ios::exceptions
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  ifstream file;
  file.exceptions ( ifstream::eofbit | ifstream::failbit | ifstream::badbit );
  try {
    file.open ("test.txt");
    while (!file.eof()) file.get();
  }
  catch (ifstream::failure e) {
    cout << "Exception opening/reading file";
  }

  file.close();

  return 0;
}

Basic template member declaration ( basic_ios<charT,traits> ):
iostate exceptions () const;
iostate exceptions ( iostate except );

See also.
  ios class


© The C++ Resources Network, 2001