ios::exceptions | public member function |
iostate exceptions ( ) const; void exceptions ( iostate except ); |
Get/set exception mask
The first function version returns the current exception mask for the stream.
The second function version sets a new exception mask and calls clear(rdstate()).
The exception mask is an internal value of all stream objects specifying which state flags have to throw an exception when they are set. This mask is an object of type ios_base::iostream, which is a value formed by any combination of the following member constants:
flag value | indicates |
---|---|
eofbit | End-Of-File reached while performing an extracting operation on an input stream. |
failbit | The last input operation failed because of an error related to the internal logic of the operation itself. |
badbit | Error due to the failure of an input/output operation on the stream buffer. |
goodbit | No error. Represents the absence of all the above (the value zero). |
More than a single state flag bit can be combined into a single bitmask by using the bitwise OR operator (|). By default, stream objects have a goodbit exception mask, which means no exceptions are thrown when any of the state flags is set.
Parameters
- except
- A 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::rdstate | Get error state flags (public member function) |