Catch WebException


using System;
using System.Net;
using System.Threading;

class ThreadTest
{
    static void Main()
    {
        WebClient wc = new WebClient();
        try
        {
            wc.Proxy = null;
            string s = wc.DownloadString("http://www.google.com");
        }
        catch (WebException ex)
        {
            if (ex.Status == WebExceptionStatus.NameResolutionFailure) 
                Console.WriteLine("Bad domain name");
            else if (ex.Status == WebExceptionStatus.ProtocolError)
            {
                HttpWebResponse response = (HttpWebResponse)ex.Response;             
                Console.WriteLine(response.StatusDescription); // "Not Found" 
                if (response.StatusCode == HttpStatusCode.NotFound)
                    Console.WriteLine("Not there!");
            }
        }
    }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.