Tuesday, 13 October 2015

Exception handling example in java (ArrayIndexOutOfBoundsException exception handling)


public class First {

public static void main(String[] args) {
// TODO Auto-generated method stub
Second obj = new Second();
obj.S();
}

}



public class Second {
int i[]=new int[5];
   void S(){
try{  i[7]=2;}
catch (ArrayIndexOutOfBoundsException a){
a.printStackTrace();
System.out.println("Catch Block.....");
}
finally{
 
System.out.println("Final Block .....");
}
  
   }
}

output:-
java.lang.ArrayIndexOutOfBoundsException: 7
at Second.S(Second.java:6)
at First.main(First.java:7)
Catch Block.....
Final Block .....


No comments:

Post a Comment