我正在扫描一个包含许多路径的 url,例如:http://url.com/path1to 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());
}
}
}