Topic: Is the exception behaviour of iostreams Implementation defined?
Author: bkline@cortex.nlm.nih.gov (Bob Kline Phoenix Contract)
Date: 1995/06/13 Raw View
greghunt@zeta.org.au wrote:
: The draft at Table 72 (27-16) shows that ios_base construction sets (in some
: way) exceptions() to goodbit. I assume that this means that no setstate()
: operation on the base class will throw and exception.
: At 27.4.4.3 iostate exceptions() const; indicates which iostates may cause
: exceptions to be thrown.
: Elsewhere (27.6.1.2.2 para 2 for example) it says that setstate(failbit) may
: throw an ios_base::failure exception. Again at 27.6.1.3 para 2 basic_istream
: may call setstate() at eof and thus possibly throw an exception.
: Is the mapping between states and exceptions implementation defined? Where
: is it set? Personally I am not fond of file system behaviour that treats
: eof as an exception but I can't see how I can know in advance what the
: exception behaviour is going to be.
: Can anyone clarify this for me? Have I missed something?
If I understand this section of the DWP correctly, the programmer
has control over which states trigger exceptions by use of the second
overloaded version of the function: void exceptions(iostate except);,
with the default behavior that no state will trigger an exception.
This works out nicely, as you have the best of both worlds, unless
I've missed some subtle pitfall. I certainly hope my understanding
is correct, as I share your distaste for an I/O package which by
default would throw an exception on eof.
--
/*----------------------------------------------------------------------*/
/* Bob Kline Stream International */
/* bob_kline@stream.com formerly Corporate Software, Inc. */
/* voice: (703) 522-0820 x-311 fax: (703) 522-5407 */
/*----------------------------------------------------------------------*/
Author: greghunt@zeta.org.au
Date: 1995/06/09 Raw View
The draft at Table 72 (27-16) shows that ios_base construction sets (in some
way) exceptions() to goodbit. I assume that this means that no setstate()
operation on the base class will throw and exception.
At 27.4.4.3 iostate exceptions() const; indicates which iostates may cause
exceptions to be thrown.
Elsewhere (27.6.1.2.2 para 2 for example) it says that setstate(failbit) may
throw an ios_base::failure exception. Again at 27.6.1.3 para 2 basic_istream
may call setstate() at eof and thus possibly throw an exception.
Is the mapping between states and exceptions implementation defined? Where
is it set? Personally I am not fond of file system behaviour that treats
eof as an exception but I can't see how I can know in advance what the
exception behaviour is going to be.
Can anyone clarify this for me? Have I missed something?