CStreamIOError

Name

CStreamIOError -- I/O error on a C++ stream.

Synopsis


#include <CStreamIOError.h>
class        CStreamIOError {
                
   CStreamIOError(IoStreamConditions eReason, const char* pDoing, std::ios& rStream);
                  CStreamIOError(IoStreamConditions eReason, const std::string& rDoing, std::ios& rStream);

                
  virtual const const char* ReasonText();
                  virtual const Int_t ReasonCode();
                  const IoStreamConditions getReason();
                  std::ios& getStream();
                  const const char* getErrorMessage();
};
               

Description

Captures an error condition reading from or writing to a C++ stream (<iostream>). The errors are captured via an enumeration CStreamIOError::IoStreamConditions. See "Types and Pulbic Data" below for more information about the values this can have.

Public member functions

CStreamIOError(IoStreamConditions eReason, const char* pDoing, std::ios& rStream); CStreamIOError(IoStreamConditions eReason, const std::string& rDoing, std::ios& rStream);

Constructs an exception object that can later be thrown. eReason is the CStreamIOError::IoStreamConditions value that describes the error being reported. See "Types and Public Data" for more information about allowed values.

pDoing or rDoing pass in the eror context string that can be reported back to the catcher.

rStream is a reference to the stream on which the error was detected.

virtual const const char* ReasonText();

Returns the reason text associated with the error. This will be a string that describes the value of the eReason used to construct the exception object.

virtual const Int_t ReasonCode();

Returns the error condition cast to an int. You can also use the class specific getReason described below.

const IoStreamConditions getReason();

Returns the reason the error was thrown.

std::ios& getStream();

Returns a reference to the failing stream. Note that if the catch handler is far enough up the call stack the stream may have been destroyed already. consider something as simple as:


try {
    ifstream something("somefile");
    somefunction(something);       // can throw...
    ...
}
catch (CStreamIOError& error) {
...
}
                

Due to the semantics of exception handling, the stream reference that would be returned would be to an already destroyed stream.

const const char* getErrorMessage();

Returns a full error message string that includes the reason for the error and the context string as well.

Types and public data

The type: CStreamIOError::IoStreamConditions is used to capture error information. Calling ReasonCode and then casting that value to an CStreamIOError::IoStreamConditions will give you one of the following values:

CStreamIOError::EndFile

An end file condition has been detected.

CStreamIOError::BadSet

The bad bit in the stream's I/O status mask is set.

CStreamIOError::FailSet

The fail bit is set in the stream's I/O status mask.