When you write non-trivial code, do you do error checking on things like printing to cout or cerr with an ostream object? How would you handle it if the << operator fails in the middle of a chain like this for example:
Code:
cout << a << b << c << d << endl;
I found myself having to overload the >> operator for a somewhat complex class, and there's just so many things that can fail that I don't know where to begin. I thought about using a sentry, but I don't really see the point of doing that since all the istream member functions automatically make use of one either way.
Since the << and >> operators don't throw unless you tell them to so with exceptions(), I don't want my own overloaded operator to do so either. But then my code starts looking very C-ish all of a sudden.
For example, how would you error check get(c), unget() etc. Should I just return if they fail and let the caller deal with whatever mayhem may have been invoked? That seems kinda nasty to do if you've already read some characters from the stream, potentially leading to data loss. But if you can't put them back into the stream what else are you going to do ...