From 228802333113613480
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,a8c910fe3fc23840,start
X-Google-Attributes: gidf78e5,public
Path: controlnews3.google.com!news1.google.com!news.glorb.com!peer1.news.newnet.co.uk!peer1.news.newnet.co.uk!kibo.news.demon.net!mutlu.news.demon.net!demon!mail2news.demon.co.uk!devnull
From: aaronblue6@cox-internet.com ("Aaron W. LaFramboise")
Newsgroups: comp.std.c++
Subject: ios::badbit set when rdstate & exceptions() causes throw ios::failure?
Date: Sat, 15 May 2004 18:43:55 +0000 (UTC)
Organization: Posted via Supernews, http://www.supernews.com
Lines: 61
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <10a7vpetcl4a868@corp.supernews.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: mail2news.demon.co.uk 1084646635 17771 10.0.0.1 (15 May 2004 18:43:55 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Sat, 15 May 2004 18:43:55 +0000 (UTC)
X-Received: from mulga.cs.mu.oz.au ([128.250.1.22])
	by news.demon.co.uk with esmtp (Exim 4.12)
	id 1BP48Y-0004cU-00
	for mail2news@news.news.demon.net; Sat, 15 May 2004 18:43:54 +0000
X-Received: from mulga.cs.mu.OZ.AU (localhost [127.0.0.1]) by mulga.cs.mu.OZ.AU with ESMTP
	id i4FIhptP000935; Sun, 16 May 2004 04:43:51 +1000 (EST)
X-Received: (from fjh@localhost)
	by mulga.cs.mu.OZ.AU (8.12.10+Sun/8.12.9/Submit) id i4FIhoG7000926;
	Sun, 16 May 2004 04:43:50 +1000 (EST)
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Path: comp-std-cpp-robomod!not-for-mail
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Delivered-To: std-c++@ucar.edu
X-Newsgroups: comp.std.c++
X-User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7b) Gecko/20040316
X-Accept-Language: en-us, en, es-mx, es-es, es
X-Spam-Checker-Version: SpamAssassin 2.60-mulga_r1 (1.212-2003-09-23-exp) on 
	mulga.cs.mu.OZ.AU
X-Spam-Level: 
X-Spam-Status: No, hits=-4.9 required=5.2 tests=BAYES_00 autolearn=ham 
	version=2.60-mulga_r1
Xref: controlnews3.google.com comp.std.c++:321

Hello,

On my implementation (GCC 3.3.2 on Win32), badbit is set as well as 
failbit and eofbit when I reach the end of an ifstream if and only if 
(exceptions() & eofbit) == true.  See the following test case:

----
#include <fstream>
#include <iostream>


int main() {

   using std::cout;

   std::ifstream in;

   in.open("/dev/null");
//  in.open("nul");

   using std::ios;

   // comment the following line
   in.exceptions(ios::failbit | ios::badbit | ios::eofbit);

   try {
     in.get();
   }
   catch(ios::failure &e) {
     cout << e.what() << '\n';
   }

   if(in.good())
     cout << "good ";
   if(in.bad())
     cout << "bad ";
   if(in.fail())
     cout << "fail ";
   if(in.eof())
     cout << "eof";
   cout << '\n';

   return 0;
}
----

On my implementation, badbit is set when this program is compiled as-is, 
but badbit is not set when "in.exceptions(..." is removed.

Can someone verify that this is correct behavior?  If so, can someone 
explain to me why badbit is being set in this case?


Aaron W. LaFramboise

---
[ 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                       ]



