title: Raise exception vs. return None in functions?
body: <p>What's better practice in a user-defined function in Python: <code>raise</code> an exception or <code>return None</code>?  For example, I have a function that finds the most recent file in a folder.</p>
  
  <pre><code>def latestpdf(folder):
      # list the files and sort them
      try:
          latest = files[-1]
      except IndexError:
          # Folder is empty.
          return None  # One possibility
          raise FileNotFoundError()  # Alternative
      else:
          return somefunc(latest)  # In my case, somefunc parses the filename
  </code></pre>
  
  <p>Another option is leave the exception and handle it in the caller code, but I figure it's more clear to deal with a <code>FileNotFoundError</code> than an <code>IndexError</code>. Or is it bad form to re-raise an exception with a different name?</p>