Handle network exceptions : Network Exception : Network C# Examples


C# Examples » Network » Network Exception »

 

Handle network exceptions









    
using  System;  
using  System.Net;  
using  System.IO;  
  
class  MainClass  {    
    public  static  void  Main()  {  
        int  ch;  
  
        try  {  
  
            HttpWebRequest  req  =  (HttpWebRequest)  WebRequest.Create("http://www.navioo.com");  
  
            HttpWebResponse  resp  =  (HttpWebResponse)  req.GetResponse();  
  
            Stream  istrm  =  resp.GetResponseStream();  
  
            for(int  i=1;  ;  i++)  {  
                ch  =    istrm.ReadByte();  
                if(ch  ==  -1)  
                      break;  
                Console.Write((char)  ch);  
            }  
  
            resp.Close();  
  
        }  catch(WebException  exc)  {  
            Console.WriteLine("Network  Error:  "  +  exc.Message  +    
                                                "\nStatus  code:  "  +  exc.Status);  
        }  catch(ProtocolViolationException  exc)  {  
            Console.WriteLine("Protocol  Error:  "  +  exc.Message);  
        }  catch(UriFormatException  exc)  {  
            Console.WriteLine("URI  Format  Error:  "  +  exc.Message);  
        }  catch(NotSupportedException  exc)  {  
            Console.WriteLine("Unknown  Protocol:  "  +  exc.Message);  
        }  catch(IOException  exc)  {  
            Console.WriteLine("I/O  Error:  "  +  exc.Message);  
        }  catch(System.Security.SecurityException  exc)  {  
            Console.WriteLine("Security  Exception:  "  +  exc.Message);  
        }  catch(InvalidOperationException  exc)  {  
            Console.WriteLine("Invalid  Operation:  "  +  exc.Message);  
        }  
    }  
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Network
» Network Exception