Topic: Streambuf extracters/inserters exception policy
Author: squell@alumina.nl (Marc)
Date: Tue, 22 Feb 2005 02:13:47 GMT Raw View
My apologies if this has been brought up before;
I was browsing through the LWG's library issue list yesterday, when I
noticed issue 413(*) dealing with 27.6.1.2.3, operator>>(streambuf*). I
feel the proposed resolution is wrong.
(*) http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#413
I interpret the error policy of the iostreams to be that ios::badbit
should be turned on whenever the underlying streambuffer has "gone bad",
whereas ios::failbit merely indicates that a single request failed.
Specifically, 27.6.1.2.1 says that when an exception gets caught during
input, this should trigger ios::badbit and conditionally re-throw.
The proposed wording contradicts this - it's the same situation (an
exception 'while extracting characters from *this'), but a different
response to it.
Wasn't this sentence intended to deal with the situation where no
characters are inserted into sb because it threw an exception - and in
that case throw the caught exception instead of ios::failure?
In that case, a more correct resolution would be:
'.. an exception thrown while inserting characters in sb ..'
But, while writing this, I get the sense there is more here: all the
iostream members that operate on streambufs have subtly different
exception policies; the ostream inserter always fails when its argument
throws, the two istream extracters only fail if an exception causes them
to insert nothing, but the exception they throw in that case won't be
the same!
Are these differences intentional? If so, why?
Dealing with two streambufs implies there are two possible sources of
errors, and I feel that they should be treated seperately (i.e. badbit
if it happens in *this, failbit if it happens in the argument), and that
any error should always be treated differently from a success condition,
since a streambuf itself has no way of informing a user about its state.
(Compare "cin >> cout.rdbuf()" with "cout << cin.rdbuf()" and assume
stdout will accept a few characters before failing. The first call will
'succeed', the second will fail and have ios::badbit set.)
Marc
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]