HttpStatusCode 404

  • Thread starter Thread starter Dan
  • Start date Start date
D

Dan

This status represents "Page Not Found". However, when I execute the code
below with a purposely bogus URL, GetResponse throws an error before I can
retrieve the 404 status. I've been told on this group that this is the way
it's supposed to work. If that's so, why is 404 included in the
HttpStatusCode enumeration at all; you can never retrieve it.

Dan

try
{
HttpWebResponse response = (HttpWebResponse) m_request.GetResponse();

Console.WriteLine("Status Code = " + response.StatusCode);
}
catch(System.Net.WebException ex)
{
Console.WriteLine(ex.ToString()); // Returns "The remote server returned an
error: (404) Not Found"
}
 
retrieve the 404 status. I've been told on this group that this is the
way
it's supposed to work. If that's so, why is 404 included in the
HttpStatusCode enumeration at all; you can never retrieve it.

Because not every return code is 404. Occasionally, a page is found.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
??? I'm not sure we're communicating here. The question is: why can you not
retrieve the status code? The exception is thrown before you even get the
chance.
 
You can retrieve the status code. Not when it's a 404, but on a number
of other occasions. As to why it's included, probably for the sake of
completeness. It just might be used in other places where there
actually is a use for the 404 entry.
/Hugo
 
Back
Top