title: Catch timeout with HttpException
body: <p>We have an image upload page that will timeout if the user's upload is taking longer than 15 minutes.</p>
  
  <p>We're catching the HttpException that occurs with a timeout. But how can we know that the exception occurred because of a timeout, so we can return a specific message?</p>
  
  <p>Our code:</p>
  
  <pre><code>try
  {
      // do stuff here
  }
  catch (HttpException ex)
  {
      // What can we check to know if this is a timeout exception?
      // if (ex == TimeOutError)
      // {
      //      return "Took too long. Please upload a smaller image.";
      // }
      return "Error with image. Try again.";
  }
  catch (Exception ex)
  {
      return "Error with image. Try again.";
  }
  </code></pre>
  
  <p>And what the timeout error looks like:</p>
  
  <pre><code>System.Web.HttpException (0x80004005): Request timed out.
  at System.Web.HttpRequest.GetEntireRawContent()
  at System.Web.HttpRequest.GetMultipartContent()
  at System.Web.HttpRequest.FillInFormCollection()
  at System.Web.HttpRequest.EnsureForm()
  at System.Web.HttpRequest.get_Form()
  at MyStore.upload.ProcessRequest(HttpContext context) 
  
  ex.ErrorCode=-2147467259
  ex.GetHttpCode=500
  ex.WebEventCode=0
  </code></pre>
  
  <p>I'm hesitant to simply do an <code>if</code> statement that compares the error codes above.</p>
  
  <p>HttpCode <code>500</code> seems to be a generic <code>Internal Server Error</code> code that could happen for more than just a timeout exception.</p>
  
  <p>ErrorCode <code>-2147467259</code> is something I'm unfamiliar with. If that number will remain constant for timeout errors, and will never occur with non-timeout exceptions, then I could do an <code>if</code> comparison on this number.</p>
  
  <p>I'm thinking there has to be a simple way to know if the <code>HttpException</code> is a timeout exception, ala something like:</p>
  
  <pre><code>if (ex == TimeoutError) // what should this be?
  </code></pre>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I just now tried catching <code>TimeoutException</code>, like the following, but it still is only caught by the <code>HttpException</code>.</p>
  
  <pre><code>try
  {
      // do stuff here
  }
  catch (TimeoutException ex)
  {
      // Timeout doesn't get caught. Must be a different type of timeout.
      // So far, timeout is only caught by HttpException.
      return "Took too long. Please upload a smaller image.";
  }
  catch (HttpException ex)
  {
      // What can we check to know if this is a timeout exception?
      // if (ex == TimeOutError)
      // {
      //      return "Took too long. Please upload a smaller image.";
      // }
      return "Error with image. Try again.";
  }
  catch (Exception ex)
  {
      return "Error with image. Try again.";
  }
  </code></pre>