Social Icons

Sunday 29 September 2013

Exception handling in java

class ex
{

 public static int quotient(int a,int b)
{

   if(b==0)
  {
  throw new ArithmeticException("divide by zero") ;
  }
 return a/b;


}


 public static void main(String args[])
 {
 int c;
 int a=5,b=0;
 

       
  try
  {
   c=quotient(a,b);
  System.out.println("the value of a/b is "+c);

  }



 catch(ArithmeticException e)
 {
  System.out.println("the b value can not be negative :");
 System.out.println(" :"+e.getMessage());
  System.out.println(" :"+e.toString());

  e.printStackTrace();
 }


     finally
       {
          System.out.println("hello finally is executed ");
 
              }            


}


}

No comments:

Post a Comment

 

Sample Text

Sample text

 
Just Programming Cse DriveReputation Management