Use the NullReferenceException. : Predefined Exception : Language Basics C# Examples


C# Examples » Language Basics » Predefined Exception »

 

Use the NullReferenceException.









    
using  System;    
    
class  MainClass  {      
    public  static  void  Main()  {      

        try  {  
            string  str  =  null;
            Console.WriteLine(str.ToString());
            
        }  catch  (NullReferenceException)  {  
            Console.WriteLine("NullReferenceException!");  
            Console.WriteLine("fixing...\n");  
  
        }  
  
    }    
}
    
   
  
   



Output

NullReferenceException!
fixing...


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Language Basics
» Predefined Exception