Why does HttpWebRequest throw an exception instead returning HttpStatusCode.NotFound? Why does HttpWebRequest throw an exception instead returning HttpStatusCode.NotFound? asp.net asp.net

Why does HttpWebRequest throw an exception instead returning HttpStatusCode.NotFound?


Ya this can be quite annoying when web pages use status codes heavily and not all of them are errors. Which can make processing the body quite a pain. Personally I use this extension method for getting the response.

public static class HttpWebResponseExt{    public static HttpWebResponse GetResponseNoException(this HttpWebRequest req)    {        try        {            return (HttpWebResponse)req.GetResponse();        }        catch (WebException we)        {            var resp = we.Response as HttpWebResponse;            if (resp == null)                throw;            return resp;        }    }}


Why not? They're both valid design options, and HttpWebRequest was just designed to work this way.