Based on this MSDN article, you could do something along the following lines:
try
{
// try to download file here
}
catch (WebException ex)
{
if (ex.Status == WebExceptionStatus.ProtocolError)
{
if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.NotFound)
{
// handle the 404 here
}
}
else if (ex.Status == WebExceptionStatus.NameResolutionFailure)
{
// handle name resolution failure
}
}
I'm not certain that WebExceptionStatus.NameResolutionFailure is the error you are seeing, but you can examine the exception that is thrown and determine what the WebExceptionStatus for that error is.
根据这篇 MSDN 文章,您可以这样做大致如下:
我不确定
WebExceptionStatus.NameResolutionFailure
是您看到的错误,但您可以检查引发的异常并确定WebExceptionStatus
因为这个错误是。Based on this MSDN article, you could do something along the following lines:
I'm not certain that
WebExceptionStatus.NameResolutionFailure
is the error you are seeing, but you can examine the exception that is thrown and determine what theWebExceptionStatus
for that error is.