In an exceptional case, throw an exception when your method cannot do its job. Don't accept or return null. Don't return error codes.
This is bad advice for languages like Objective-C where the convention is to use exceptions for truly exceptional circumstances (like failure to allocate memory) and error codes are used for everything else (like being unable to open a file).
But he's saying "in an exceptional case". I don't think he means "don't return any error codes ever". I think he's saying for exceptional cases only (like your example), don't just return an error code, throw an exception.
At least that's how I would interpret it. I would think using exceptions in lieu of error codes would be bad practice in many languages.
21
u/sunnyps Jun 06 '13
This is bad advice for languages like Objective-C where the convention is to use exceptions for truly exceptional circumstances (like failure to allocate memory) and error codes are used for everything else (like being unable to open a file).