我正在扫描一个有很多路径示例的网址:http://url.com/path1到1000.有时我会得到一个WebException但是在我的catch块中,NullReferenceException如果我不使用该行,它将引发错误
if (x.Status == WebExceptionStatus.ProtocolError && x.Response != null)
所以我的问题是:下面的代码是修复错误还是忽略它?
错误没有特定的错误路径只是随机像http://url.com/path10或任何其他链接谢谢:)
catch (WebException x)
{
if (x.Status == WebExceptionStatus.ProtocolError && x.Response != null)
{
HttpWebResponse response = (HttpWebResponse)x.Response;
if (response.StatusCode == HttpStatusCode.NotFound)
{
listBox3.Items.add(listBox1.Items[i].ToString());
}
}
}
Run Code Online (Sandbox Code Playgroud)