try catch exception when

static void WebClientDemo()
        {
            string str = null;
            using(WebClient wc=new WebClient())
            {
                try
                {
                    str = wc.DownloadString("http://www.albahari.com/nutshell/");
                    Console.WriteLine(str);
                }
                catch (WebException ex) when (ex.Status == WebExceptionStatus.Timeout)
                {
                    Console.WriteLine("Timeout");
                }
            }
        }
原文地址:https://www.cnblogs.com/Fred1987/p/12733006.html