Exception Handling First Program

Exception Handling First Program with try and catch Statement


    Program with try and catch Statement

     
                    
                 public class ExceptionManager
                 {
                    public static void main(String[] args) 
                    {
                       try
                       
                       {
                          System.out.println("Main Begin");
                          String s1  = args[0];
                          System.out.println("Input is  : "+s1);
                          int i  =  Integer.parseInt(s1);
                          System.out.println("Integer Parameter is "+i);
                          int k  = (int)(i/(i-9));
                          System.out.println(k);
                       }
                       catch (ArrayIndexOutOfBoundsException ex)
                       {
                          System.out.println("Array size given but not pass any value");
                       }
                       catch (NumberFormatException ex)
                       {
                          System.out.println("String value not convert into int so you enter int value");
                       }
                       catch (ArithmeticException ex)
                       {
                          System.out.println("divisible by zero is not allow");
                       }
                       System.out.println("End");
                    }
                 }                
    Different Run Program with Exception Handaling

        jd: sdj_batch>java ExceptionManager

           Main Begin
           Array size given but not pass any value
           End

        d: sdj_batch>java ExceptionManager 9

           Main Begin
           Input is : 9
           Integer Parameter is 9
           divisible by zero is not allow
           End

        d:\sdj_batch\java ExceptionManager praveen

           Main Begin
           Input is: Praveen
           String value not converts into int so you enter int value
           End

        d:\sdj_batch\java ExceptionManager “18”

           Main Begin
           Input is : 18
           Integer Parameter is 18
           2
           End