title: Python: Getting a WindowsError instead of an IOError
body: <p>I am trying to understand exceptions with Python 2.7.6, on Windows 8.</p>
  
  <p>Here's the code I am testing, which aims to create a new directory at <code>My_New_Dir</code>. If the directory already exists, I want to delete the entire directory and its contents, and then create a fresh directory.</p>
  
  <pre><code>import os
  
  dir = 'My_New_Dir'
  try:
      os.mkdir(dir)
  except IOError as e:
      print 'exception thrown'
      shutil.rmtree(dir)
      os.mkdir(dir)
  </code></pre>
  
  <p>The thing is, the exception is never thrown. The code works fine if the directory does not already exist, but if the directory does exist, then I get the error: </p>
  
  <blockquote>
    <p>WindowsError: [Error 183] Cannot create a file when that file already exists: 'My_New_Dir'</p>
  </blockquote>
  
  <p>But according to the Python documentation for os.mkdir(),</p>
  
  <blockquote>
    <p>If the directory already exists, OSError is raised.</p>
  </blockquote>
  
  <p>So why is the Windows error being thrown, rather than the Python exception?</p>