exception handle program example in java

/*6.1. Write a program that divides two numbers. Handle all exceptions that can be generated in this program.*/

class  E
{
   public static void main(String []args)
     {
        try
         {
          int a=5;
        System.out.println(a/0);
        System.out.println("just check karva ");
     }
      catch(ArithmeticException  e)
       {
            System.out.println("exceptin is ="  +e.getMessage());
      }
System.out.println("print thay k nai joy");
}
}


*************************************
default catch


class  Etry
{
   public static void main(String []args)
     {
        try
         {
          int a=5;
        System.out.println(a/0);
        System.out.println("just check karva ");
     }
      catch(NullPointerException  e)   // bcz here Arithmetic exception occure
       {
            System.out.println("exceptin is ="  +e.getMessage());
      }
System.out.println("print thay k nai joy");
}
}

Comments

Popular posts from this blog

Write a java program to calculate gross salary & net salary taking the following data

WAP a program that illustrates interface inheritance. Create two interface p1 and p2 . create Interface p which extends p1 and p2 and then create interface p12 which extends p12. Each interface declare one constants and one method. Create class Q which implements p12 and define all the methods of interface which displays value of constants

Example of abstract class