title: Catching COMException specific Error Code
body: <p>I'm hoping someone can help me. I've got a specific Exception from COM that I need to catch and then attempt to do something else, all others should be ignored. My error message with the Exception is:</p>
  
  <blockquote>
    <p>System.Runtime.InteropServices.COMException
    (0x800A03EC): Microsoft Office Excel
    cannot access the file 'C:\test.xls'.
    There are several possible reasons:</p>
  </blockquote>
  
  <p>So my initial attempt was </p>
  
  <pre><code>try
  {
   // something
  }
  catch (COMException ce)
  {
     if (ce.ErrorCode == 0x800A03EC)
     {
        // try something else 
     }
  }
  </code></pre>
  
  <p>However then I read a compiler warning:</p>
  
  <blockquote>
    <p>Warning   22  Comparison to integral
    constant is useless; the constant is
    outside the range of type
    'int' .....ExcelReader.cs 629 21</p>
  </blockquote>
  
  <p>Now I know the 0x800A03EC is the
  HResult and I've just looked on MSDN
  and read:</p>
  
  <blockquote>
    <p>HRESULT is a 32-bit value,
    divided into three different fields: a
    severity code, a facility code, and an
    error code. The severity code
    indicates whether the return value
    represents information, warning, or
    error. The facility code identifies
    the area of the system responsible for
    the error.</p>
  </blockquote>
  
  <p>So my ultimate question, is how do I ensure that I trap that specific exception? Or how do I get the error code from the HResult?</p>
  
  <p>Thanks in advance.</p>