Handling Errors Using the Stream Status Functions
The following code shows how to handle errors using the stream status functions:
filebuf fbuf;
fbuf.open("someFile", ios::in); // 1
RWCharInputStream charInputStream =
RWCharFromStreambufInputStreamImp::make(fbuf); // 2
RWCString line;
RWSize lineNumber=1;
while(1) {
line= "";
charInputStream.readUntil(line,'\n'); // 3
if(charInputStream.isGood()) // 4
cout << lineNumber++ << ": " << line << endl;
else
break;
}
if(charInputStream.isEof()) // 5
cout << "We have reached EOF" << endl;
Other errors are reported by throwing an instance of one of the two exception classes provided by the Streams package.
Classes
RWxmsg and
RWExternalErr are included in the Essential Tools Module.