title: How to handle FileNotFoundError when "try .. except IOError" does not catch it?
body: <p>How can I catch an error on python 3? I've googled a lot but none of the answers seem to be working. The file open.txt doesn't exist so it should print e.errno.</p>
  
  <p>This is what I tried now:</p>
  
  <p>This is in my defined function</p>
  
  <pre><code>try:
      with open(file, 'r') as file:
          file = file.read()
          return file.encode('UTF-8')
  except OSError as e:
      print(e.errno)
  </code></pre>
  
  <p>However I does not print anything when I get this error</p>
  
  <pre><code>FileNotFoundError: [Errno 2] No such file or directory: 'test.txt'
  </code></pre>