4 ms·
I tell you the right answer and anyone who disagrees is wrong. Never return error codes, always return results. A function that reads a file into lines and you
by bjourne 2y ago
I tell you the right answer and anyone who disagrees is wrong.
Never return error codes, always return results. A function that reads a file into lines and you can't do that? Throw exception. Can't restart some service? Again, throw. Throwing is almost always right, unless the failure itself is a legitimate result. For example, a parser should probably not throw on errors and should instead return a ParseResult which is either a ParseTree or a ParseError containing (at least) an error code for the computer and an error message for the human. However, a parser should never return an error for say, a divide by zero or out of memory error (though a garbage collector could), since those aren't really parse errors.
See https://wiki.c2.com/?SamuraiPrinciple https://wiki.c2.com/?SamuraiPrinciple and related pages.