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");
                }
            }
        }

 

posted @ 2020-04-19 19:19  FredGrit  阅读(238)  评论(0编辑  收藏  举报