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:
Parameters.
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