Throwing Exceptions : Predefined Exception : Language Basics C# Examples


C# Examples » Language Basics » Predefined Exception »

 

Throwing Exceptions









    
using  System;

class  MainClass
{
      static  void  Main()
      {
            string  arg  =  null;
            
            try
            {
                  if  (arg  ==  null)
                  {
                        ArgumentNullException  MyEx  =  new  ArgumentNullException();
                        throw  MyEx;
                  }
            }
            catch  (ArgumentNullException  e)
            {
                  Console.WriteLine("Message:  {0}",  e.Message);
            }
      }
}
    
   
  
   



Output

Message: Value cannot be null.


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Language Basics
» Predefined Exception