I have some kind of ideological question, therefore:
Suppose I have a template function
template <typename Stream>
void Foo(Stream& stream, Object& object) { ... }
which does something with this objectand stream(e.g. serializes this object for a stream or something like that).
Let's say I also add some simple wrappers, for example (and let the number of these wrappers be 2 or 3):
void FooToFile(const std::string& filename, Object& object)
{
std::ifstream stream(filename.c_str());
Foo(stream, object);
}
So my question is:
Where in this case (ideologically) should I throw an exception if mine is streambad? Should I do this in every shell or just transfer this check to mine Fooso that the body looks like
if (!foo.good()) throw (something);
I understand that this may not be the most important part of coding, and these solutions are actually equal, but I just don't know the “right” way to implement this.
Thank.