title: Exception codes, or detecting a "file already exists" type exception
body: <p>In trying to answer <a href="https://stackoverflow.com/questions/12388895/showing-the-dialog-of-the-file-already-existence-at-the-location">this question</a>, I was surprised to discover that attempting to create a new file when that file already exists does not throw a unique exception type, it just throws a generic <code>IOException</code>.</p>
  
  <p>I am therefore left wondering how to determine if the <code>IOException</code> is the result of an existing file, or some other IO error. </p>
  
  <p>The exception has an HResult, but this property is protected, and thus unavailable to me.</p>
  
  <p>The only other way I can see is to pattern match the message string which feels awful.</p>
  
  <p>example:</p>
  
  <pre><code>try
  {
      using (var stream = new FileStream("C:\\Test.txt", FileMode.CreateNew))
      using (var writer = new StreamWriter(stream))
      {
          //write file
      }
  }
  catch (IOException e)
  {
      //how do I know this is because a file exists?
  }
  </code></pre>