Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 3
    Yup. If you've got an error condition, throw an exception. Commented Aug 13, 2009 at 21:56
  • 3
    This is one case where an exception would be warranted. If you're requesting the name of an employee that doesn't exist, something is obviously going wrong. Commented Aug 13, 2009 at 22:03
  • I think that's a bit literal, Thorarin-you can quibble with my example, certainly, but I'm sure you can imagine some instance of a function that returns a matching value, or null if there's no match. How about getting a value from a key in a hashtable? (should've thought of that example in the first place). Commented Aug 14, 2009 at 15:06
  • 1
    A hash table returning null for a key that doesn't exist is bad. Doing so automatically means that you can't store null as a value without inconsistent code. Commented Aug 27, 2009 at 13:51