C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Streambuf extracters/inserters exception policy

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Marc
Guest





PostPosted: Tue Feb 22, 2005 2:13 am    Post subject: Streambuf extracters/inserters exception policy Reply with quote



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 ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.