[C++] which is better, throw an exception or return nonzero value?
- by xis19
While you are doing C++ programming, you have two choices of reporting an error. I suppose many teachers would suggest you throw an exception, which is derived from std::exception. Another way, which might be more "C" style, is to return a non-zero value, as zero is "ERROR_SUCCESS".
Definitively, return an exception can provide much more information of the error and recovery; while the code will bloat a little bit, and making exception-safe in your mind is a little difficult for me, at least. Other way like returning something else, will make reporting an error much easier; the defect is that managing recovery will be a possibly big problem.
So folks, as good programmers, which would be your preference, not considering your boss' opinion? For me, I would like to return some nonzero values.