This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of TC1 status.

61. Ambiguity in iostreams exception policy

Section: [istream.unformatted] Status: TC1 Submitter: Matt Austern Opened: 1998-08-06 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [istream.unformatted].

View all issues with TC1 status.


The introduction to the section on unformatted input ( says that every unformatted input function catches all exceptions that were thrown during input, sets badbit, and then conditionally rethrows the exception. That seems clear enough. Several of the specific functions, however, such as get() and read(), are documented in some circumstances as setting eofbit and/or failbit. (The standard notes, correctly, that setting eofbit or failbit can sometimes result in an exception being thrown.) The question: if one of these functions throws an exception triggered by setting failbit, is this an exception "thrown during input" and hence covered by, or does only refer to a limited class of exceptions? Just to make this concrete, suppose you have the following snippet.

  char buffer[N];
  istream is;
  is.exceptions(istream::failbit); // Throw on failbit but not on badbit., N);

Now suppose we reach EOF before we've read N characters. What iostate bits can we expect to be set, and what exception (if any) will be thrown?

Proposed resolution:

In, paragraph 1, after the sentence that begins "If an exception is thrown...", add the following parenthetical comment: "(Exceptions thrown from basic_ios<>::clear() are not caught or rethrown.)"


The LWG looked to two alternative wordings, and choose the proposed resolution as better standardese.