Exception Handling - Coder's point

Monday, March 25, 2019

Exception Handling

 public class MultipleCatchBlocks  
 {  
      public static void main( String args[ ] )  
      {  
           int x = 5 , y = 0 , z;  
           String children[] = { "Sridhar", "Jyothi", "Jyothna" };  
           try  
           {  
           System.out.println(z = x/y);  
           System.out.println(children[3]);  
           }  
           catch(ArithmeticException e)   
           {  
           System.out.println("Division by zero. " + e);  
           }  
           catch(ArrayIndexOutOfBoundsException e)   
           {  
           System.out.println("Array Index problem. " + e);  
           }  
      }     
 }   
OUTPUT :
Division by zero. java.lang.ArithmeticException: / by zero

No comments:

Post a Comment