404 Exceptions

by Jim Jul 18, 2006 10:07 PM

One of the rules of exception handling is to not use exceptions as flow control devices. If an exception can be anticipated, avoid it by testing for the problem condition in the first place.

That's fine, until the .NET framework doesn't give me the option of testing for the condition. I want to use WebClient or WebRequest to get a file from a web server, if it exists. But, there's no way to test for the existence of the file without throwing an exception! The server returns headers and a response stream for a 404, just like any other request - shouldn't I be able to suppress the exceptions and check for the 404 myself?

It's only going to happen a few times in my application, so maybe it's not so bad. But it's still ugly.

Tags:

Add comment


(Shows Gravatar icon; will not be displayed)

  Country flag
Click to change captcha
biuquote
  • Comment
  • Preview
Loading