Catch System.NullReferenceException : Try Catch : Language Basics C# Examples


C# Examples » Language Basics » Try Catch »

 

Catch System.NullReferenceException









    
using  System;

class  MainClass
{
      static  void  Main()
      {
            try  {  
            
                  string  str  =  null;
                  str.ToUpper();
            
            }catch  (System.NullReferenceException)  {  
            
                  Console.WriteLine("catch  clause");  
            
            }  finally  {  
            
                  Console.WriteLine("finally  clause");  
            
            }
      }
}
    
   
  
   



Output

catch clause
finally clause


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Language Basics
» Try Catch