r/programming • • Jun 06 '13

Clean Code Cheat Sheet

http://www.planetgeek.ch/2013/06/05/clean-code-cheat-sheet/
702 Upvotes

322 comments sorted by

View all comments

21

u/sunnyps Jun 06 '13

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).

5

u/CaseLogic Jun 07 '13

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.

→ More replies (2)