转自:http://stackoverflow.com/questions/175532/return-null-or-throw-exception
I have a method that is suppose to return an object if it is found.
If it is not found, should I:
a) return null
b) throw an exception
c) other
if you are always expecting to find a value then throw the exception if it is missing. The exception would mean that there was a problem.
If the value can be missing or present and both are valid for the application logic then return a null.
More important: What do you do other places in the code? Consistency is important.