Streams Package Exception Classes
Class RWExternalStreamException is the base class for all exception classes in the Streams package. It returns an error message that can be accessed through the inherited member function why(), and an error code that can be accessed through the member function errorCode(). The errorCode() function returns a value of type ErrorCode, which is an enumeration. Error codes 0 through 11 have the following meaning:
ok
everything is fine
flush
error while flushing the stream
write
error while writing to the stream
read
error while reading an RWByte, char, wchar_t, or RWUChar
get
error while reading a datatype
internalOstream
the internal ostream object is in a fail or bad state
internalIstream
the internal istream object is in a fail or bad state
featureNotSupported
reports a feature not currently supported due to compiler limitation
outOfMemory
the last memory allocation request failed
invalidParameter
one of the parameters has been assigned an invalid value
invalidUnicodeEncoding
a sequence of RWUChar does not represent a valid sequence of UTF-16 character(s)
invalidUTF8Encoding
a sequence of bytes is not formatted according to UTF-8
Error codes 12 through 499 are not currently assigned, but are reserved by Rogue Wave for future use. If you want to return your own error code, use a value greater or equal to 500.
Class RWIncompleteStreamOperation is thrown to report operations that have been partially fulfilled. For instance, an output stream function writing an array of elements might write several elements before encountering a fatal error. In this case, the function throws an instance of class RWIncompleteStreamOperation, which can be queried using the member function elementsProcessed() to get the number of elements successfully written prior to failure.
The following code shows how to handle stream exceptions:
 
try {
// some stream operation
}
catch(const RWIncompleteStreamOperation& e) {
cout << e.why() << endl;
cout << "the number of element(s) successfully processed is: "
<< e.elementsProcessed() << endl;
if (e.errorCode() == RWExternalStreamException::outOfMemory)
cout << “we ran out of memory” << endl;
}
catch(const RWExternalStreamException& e) {
cout << e.why() << endl;
if (e.errorCode() == RWExternalStreamException::outOfMemory)
cout << “we ran out of memory” << endl;
}