Tag Archives: null

Return Null or Exception?

I am writing a getter function, and the requested object can not be found.  Do I return null?   Or do I throw an exception?  The answer is “it depends.”  Sometimes both options are needed, but how to decide?

Posted in Coding, Example Code, practice | Tagged , , , | Leave a comment

Is Non-existence an Error?

You call a method to retrieve information about an object with a  particular ID, but the record does not exist.  Is this an exception?   Or not?  It is hard to answer.

Posted in Coding | Tagged , , | Leave a comment

#10 Indicate what happens when function can't return value

There are many functions which take a value, go and look for something, and return an object. If the object is found it is returned, but if it is not found, what do you do?  There are two possibilities, either … Continue reading

Posted in Coding | Tagged , , , | Leave a comment

#7 Functions Returning Collections, should never return null

A function that returns a collection, such as a list of all files in a folder, all sections on a page, or all attachments on a web site, should never return null.  It is a simple rule, and if followed … Continue reading

Posted in Coding | Tagged , | Leave a comment