exceptions

Sets the stream to throw exceptions instead of silently ignoring the error conditions specified. Without parameters returns the current setting.

The setting is composed by ORing together bits for the conditions to throw on. The following code enables all exceptions on stream s.

   s.exceptions(std::ios::badbit | std::ios::failbit | std::ios::eofbit);

Related Topics: bad, clear, eof, fail, good, rdstate

Stream states:

  • if (s): The previous operation was successful (a shorthand for !s.fail()).
  • if (s.fail()): The previous operation failed.
  • if (s.eof()): Reading past the end has been attempted.
  • if (s.bad()): Stream state is undefined; the stream can no longer be used.
  • if (s.good()): None of bad/eof/fail are set.