Throw Exception from a function : Exception Throw : Language Basics C# Examples


C# Examples » Language Basics » Exception Throw »

 

Throw Exception from a function









    
using  System;

class  MainClass
{
        
        static  void  AFunction()
        {
                int  Zero  =  0;
                int  j  =  22  /  Zero;
        }
        public  static  void  Main()
        {
                try
                {
                        Console.WriteLine("efore  Function");
                        AFunction();
                }
                catch  (DivideByZeroException  e)
                {
                        Console.WriteLine("DivideByZero  {0}",  e);
                }
        }
}
    
   
  
   



Output

efore Function
DivideByZero System.DivideByZeroException: Attempted to divide by zero.
   at MainClass.Main()


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Language Basics
» Exception Throw