I work on a legacy code in c++ which uses error codes instead of exceptions.
In this case, fn A() calls B() which calls C() etc.
Now if C() returns the error, i would like to exit at B() itself without having to pass it back to A() and have A() handle the error. However few other team members have the top most function do the error handling. Now which one would be good?
Also in the latter case, since we dont exit early enough, there happens to be multiple return statements. No i have heard somewhere that multiple return in a function should be avoided. If i avoid return then there are nested ifs to deal with.
I think that errors should be handled as locally as possible. That is, if a class’ method has enough knowledge to handle an error, it should do so. However, if the way to handle an error si to exit the program, I think this criterion doesn’t apply. In that case, you should return back in a phased manner, like @Als says, and have a single exit point. In other cases, handle the error as locally as possible.