Node:Errors, Next:, Previous:Wrapping around iostream, Up:Usage


When doing stream I/O, some unpredictable situations can occur at runtime. Binary streams are no exception to this phenomenon. To provide some sort of protection against this, all libbinio classes inherit an error reporting method called error().

It is a good idea to check the error status of a stream once in a while to see if everything is still in place. error() returns a variable of type Error, which holds the actual error value for you to check. Refer to Reference for information about the possible values of this variable and their meaning.

A status of no error is always reported with a value of 0, so you can easily check if everything is still okay in a simple if construct, like this:

       // an error occured, do something to cure it...
       // everything is still okay!

One convenience error reporting method is also included, that only checks for the Eof error status, indicating whether the end of the stream has already been reached. It is simply called eof() and returns a boolean value, indicating the end of the stream.

Whenever you call one of the error() or eof() methods, the internal error variable is reset to the "no error" state and a subsequent call to one of these methods will return NoError again.