Re: Providing diagnostic information upon successful completion
Nicola Musatti wrote:
Hallo,
I'm looking for advice on how to provide diagnostic information related
to a function call that executed successfully.
[...]
I see a few alternatives:
1) Throw a "warning" exception, which may contain the function's
return value when one is expected;
2) Return a special object which combines the return value with
optional diag info,
[...]
the decision to use such a strategic approach is best left
to the users of my library.
Consider the iostreams way:
void f()
{
string line;
getline(cin, line);
if (!cin) {
cout << "input failed - returning";
return;
}
cin.exceptions(ios::eofbit);
try {
getline(cin, line);
} catch (exception &e) {
cout << "input failed - rethrowing";
throw;
}
}
User may choose a level and/or conditions at which to throw.
--
Andrei Polushin
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]