title: Hooking up Polly Policy
body: <p>Can someone advice why my Policy handle is not handling my WebException error when I know for a fact that the code hit a WebException for a 429 problem? I've been researching this for a while now and need some help.</p>
  
  <p>This is my Polly Policy:</p>
  
  <blockquote>
  <pre><code>return Policy.Handle&lt;WebException&gt;()
              .WaitAndRetry(15, // We can also do this with WaitAndRetryForever... but chose WaitAndRetry this time.
              attempt =&gt; TimeSpan.FromSeconds(0.1 * Math.Pow(2, attempt)), // Back off!  2, 4, 8, 16 etc times 1/4-second
              (exception, calculatedWaitDuration) =&gt;  // Capture some info for logging! if needed
              {
                  // This is your new exception handler! 
                  Debug.WriteLine("Retry count: " + retries++);
                  Debug.WriteLine("Wait Duration: " + calculatedWaitDuration);
              });
  </code></pre>
  </blockquote>
  
  <p>I'm using it like this:</p>
  
  <pre><code> webResponseWaitRetryPolicy.Execute(() =&gt;
          {
              // Make a request and get a response
              UriBuilder builder = new UriBuilder(options.BaseUrl);
                  builder.Port = -1;
                  var query = HttpUtility.ParseQueryString(builder.Query);
                  /// handle parameters
                  query["client_key"] = options.ClientKey;
                  query["model_id"] = model;
                  query["image_url"] = imageUrl;
  
                  builder.Query = query.ToString();
                  string url = builder.ToString();
                  string content = string.Empty;
  
                  Result objResult;
                 HttpWebResponse response = null;
  
  
                  HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                  request.AutomaticDecompression = DecompressionMethods.GZip;
                  try
                  {
                     response = (HttpWebResponse)request.GetResponse();
                      if (response.StatusCode == HttpStatusCode.OK)
                      {
                          using (Stream stream = response.GetResponseStream())
                          using (StreamReader reader = new StreamReader(stream))
                          {
                              content = reader.ReadToEnd();
                          }
  
                          objResult = JsonConvert.DeserializeObject&lt;Result&gt;(content);
  
  
                  }
                  catch(WebException ex)
                  {
                      eventualFailures++; 
                      Debug.WriteLine("Failure: " + eventualFailures);
  
  
                  }
              });
  
          return objResult;
      }
  </code></pre>
  
  <p>When I run the code, I can see that it trigger the WebException but the Policy is not being called. Please help.</p>