2:35 am - Friday April 19, 2019

Basic exception program using array OutofBound Exception

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

//*@author :CandidJava.com
//*@descriptions : This program explain the function and use of ArrayOutOfBound Exception



class ArrayException {

public static void main(String[] args) {

//The exception should be define under the Try-Catch block

Try   {

//Initialize an array with the size of 9

int a[] =new int[9];

//The for get the array list variables upto 10

for(int i = 0; i<=10; i++){

a[i]=i;

}

}

//The catch block send an exception because in for loop it get variables from list is 10 but the list size is 9

catch(Exception e)

{

System.out.println("Exception:"+e);

}

}

}

 

Output:

D:\Candid Java\Util\ Exception>javac ArrayException.java

D:\CandidJava\ Util\Exception>java ArrayException

Exception:java.lang.ArrayIndexOutOfBoundsException: 9

 

Filed in: Z-A All Java Codes

No comments yet.

Leave a Reply