Search code examples
c#try-catchgetresponsestream

try-catch on WebException not working


i have problem With HttpWebRequest.getResponse(). My try catch don't catch my response :/. Here is code: proxy and ports are good

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){ }

Still getting window with error: https://i.sstatic.net/MriAT.jpg


Solution

  • It's likely that your try/catch is catching your exception; however, execution is breaking because you have first-chance exception debugging enabled. If you press "Continue", your program will proceed as expected. To alter this behaviour, just click the "Debug" menu, "Exceptions...", and untick the "Thrown" checkbox for CLR exceptions.

    enter image description here