Topic: ofstream failure reason


Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/05/22
Raw View
In article 3ED@tigadmin.ml.com, mansionj@gstldn9.merrill (James Mansion LADS LDN X4923) writes:
>(Don't have the draft yet I'm afraid so apologies if this is answered there but ...)
>
>If a failure occurs on ofstream (say) is there a relaible way to get any information
>about the cause of the failure? (like errno, say?)

"errno" isn't all that reliable, since it only reflects the last value
that was stored in it by any function.

No specific error reports are in the standard (nor in the C standard),
mostly because there isn't much you can say portably about stream errors.

The draft standard specifies an exception class for iostreams, which has
a what() member returning a char*. This might contain helpful information,
but has no mandated contents. (You can turn exceptions on and off for
specific error state bits in a stream.)

Apart from that, you can determine whether you hit eof, or had badly-
formatted input data, or had some other sort of problem, via the
usual error state bits. You can also test the stream (explicitly or
implicitly via enabling exceptions) at interesting points in the program,
like when you open a file and after a given read or write, to get early
notice about things going wrong.

If you need to differentiate a missing file from wrong file permissions
from device failure, you need to go outside what is in the standard.
---
Steve Clamage, stephen.clamage@eng.sun.com







Author: mansionj@gstldn9.merrill (James Mansion LADS LDN X4923)
Date: 1995/05/12
Raw View
(Don't have the draft yet I'm afraid so apologies if this is answered there but ...)

If a failure occurs on ofstream (say) is there a relaible way to get any information
about the cause of the failure? (like errno, say?)

James