TITLE: enforcing checking for error return values (Newsgroups: comp.lang.c++.moderated, 10 Feb 2000) [ There is a Fallible template class which does something similar to this. You can search the cpptips website for details. -allan ] CASPI: Ziv Caspi wrote in message > (To Andrei: No matter what you do clients can still ignore > you error codes, simply by passing a dummy variable whose > name is not the one you chose. At a certain point, you simply > have to let go.) ALEXANDRESCU: "Andrei Alexandrescu" All: Thank you very, very much for the insights you shared with me. I think this led me to finding a very nice error passing policy if you cannot use exceptions. Consider this: class Error { int code_; #ifndef NDEBUG bool checked_; #endif public: operator bool() const { #ifndef NDEBUG checked_ = true; #endif return code_ == OK; } int GetCode() { return code_; } ~Error() { #ifndef NDEBUG if (!checked_) { Dialog("You did NOT check whether an error occured. Your code has a bug."); } #endif } }; Now I have my functions return objects of class Error. This class has the best of all worlds: * it allows you to test errors with the simple policy "true is okay, false is bad". * you have access to the error code with Error::GetCode() * No threading problems * in debug mode, programmers who did not test for an error will be warned, thus tremendously easying debugging and application correctness * in release mode, the cost of passing Error around is that of an integer (or whatever the type is). I'm very happy with this solution. Of course, it still doesn't prevent perverse programmers from saying: (bool) Fun(); but I ignore perversity. I care only about carelesness. TRIBBLE: David R Tribble david@tribble.com (private correspondenc) This looks a lot like an article in the May 2000 issue of C/C++ Users Journal, "Catching Untested Return Codes" by Marc Guillemot. See . _______________________________________________ cpptips mailing list http://cpptips.hyperformix.com