How to bypass and continue after getting HttpRequest error
<p>I've got the following code.  (I don't know if I'm capturing this right in terms of my goal...to log and continue on)</p>

<pre><code>        // Create the atual Request instance
        HttpWebRequest request = CreateWebRequest(requestURI, data.Length);
        request.ContentLength = data.Length;
        request.KeepAlive = false;
        request.Timeout = 30000;

        try
        {
            requestStream = request.GetRequestStream();
            requestStream.Write(data, 0, data.Length);
            requestStream.Close();

            // get response
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            using (response)
            {
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    _requestError = true;
                    string message = String.Format("POST failed. Received HTTP {0}", response.StatusCode);
                    throw new ApplicationException(message);
                }

                responseStream = response.GetResponseStream();
            }
        }
        catch (Exception ex)
        {
            _requestError = true;
        }
</code></pre>

<p>The remote name could not be resolved: 'api10.aaa.com'
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.</p>

<p>Exception Details: System.Net.WebException: The remote name could not be resolved: 'api10.aaa.com'</p>

<pre><code>Source Error:

Line 87:                     {
Line 88:                         if (response.StatusCode != HttpStatusCode.OK)
Line 89:                         {
Line 90:                             _requestError = true;
Line 91:                             string message = String.Format("POST failed. Received HTTP {0}", response.StatusCode);
</code></pre>

<p>our global.asax ApplicationError picks up any errors in the stack.</p>

<p><strong>Now my problem:</strong>  I purposely changed the Uri this time to be invalid so that I would get an error for testing purposes and added in the _requestError boo private field flag which I want to expose if there's ever an error during a request.  Because I want to test cases where the request fails.  If the request fails, I want to be able to log and move on...not stop.  Right now, it stops.  I want to be able to access the _requestError through a public property that I expose.  This code above is actually in a base request class.  In one of my code-behinds, I am using an instance of this class and the code above is called.  I want to be able to get a bool flag, the requestError if anything major happens becuause in the code behind I wnat to log it to some tables...not our log tables, but for some other stuff related to some business logic and a certian other object.  So my point is, I'm not able to get this code to not halt the runtime.  I want to continue after this error happens otherwise I will never get the chance to utilize my public property baed off _requestError.</p>
