5

Return null or throw exception, that's the question!

Comments
  • 1
    Null: there is no data(enpty file, ...)
    Exception: error while processing data(no right to read, socket closed, format error, ...)
  • 0
    Exception always. Unless Null is specified in the docs.
  • 0
    System.exit() is better.
  • 0
    I personally like to throw exceptions when something can't be processed
  • 1
    Format system partition to ensure you get the point across that your function had nothing to return, regardless if whether it was because of an error or there was no data.

    Disclaimer: Please don't actually do this
  • 0
    Why not both

    return new exception(null)
  • 0
    @spacem
    That's how we can REALLY fuck up the app :-)
  • 1
    <quote>"If you are tempted to return null from a method, consider throwing an exception or returning a special object"</quote> Robert C Martin Clean Code, i read this today, i haven't read the entire book yet, but it seems a pretty nice book
Add Comment