WebException上的try-catch无法正常工作

时间:2014-08-02 16:25:25

标签: c# try-catch getresponsestream

我有HttpWebRequest.getResponse()的问题。我的尝试抓住了我的回答:/。这是代码: 代理和端口都很好

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.google.com/");
        req.Proxy = new WebProxy(Host, Port);
        req.Method = "GET";
        req.KeepAlive = false;
        req.Timeout = 10000;
        req.ContentType = "text/xml";

      try
        {
            using (WebResponse response = req.GetResponse())
            {
                using (Stream stream = response.GetResponseStream())
                {

                }
            }

        }
        catch (WebException) { }
        catch (Exception){ }

仍然出现错误窗口:http://i.imgur.com/yRPB2NV.jpg

1 个答案:

答案 0 :(得分:3)

您的try / catch 可能捕获您的异常;但是,执行正在中断,因为您启用了第一次机会异常调试。如果按"继续",您的程序将按预期进行。要改变这种行为,只需单击" Debug"菜单,"例外......",并解开" Thrown" CLR例外的复选框。

enter image description here