小编ter*_*la7的帖子

WebException Response属性返回null

我正在扫描一个有很多路径示例的网址:http://url.com/path11000.有时我会得到一个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)

.net c# error-handling httpwebresponse

2
推荐指数
1
解决办法
4281
查看次数

标签 统计

.net ×1

c# ×1

error-handling ×1

httpwebresponse ×1