Online Hibernate Training just in Rs. 1000

One week online training in Hibernate ORM framework. Learn Hibernate Framework and enhance your skills. Best Online Hibernate training at 90% discount. Join Now!! Offer is valid Only for limited Period!!! Online Training

ArrayIndexOutOfBoundsException

In this example we are going to see how we can catch the exception ArrayIndexOutOfBoundException. ArrayIndexOutOfBoundException is thrown when we have to indicate that an array has been accessed with an illegal index.

Ads

ArrayIndexOutOfBoundsException

        

In this example we are going to see how we can catch the exception ArrayIndexOutOfBoundException. ArrayIndexOutOfBoundException is thrown when we have to indicate that an array has been accessed with an illegal index.  

Suppose we have declared an array of int and the size of the array is 6, that means  that this array can store six values. Now suppose if want to access the seventh variable which does not exist, then it will throws the exception ArrayIndexOutOfBound. It means that there is no other value instead after that we are forcing the array to give the next value.  

The code of the program is given below:

 

<HTML>

 <HEAD>
 <TITLE>Catching an ArrayIndexOutOfBoundsException</TITLE>
 </HEAD>

<BODY>
  <H1> ArrayIndexOutOfBoundsException in jsp</H1>
   
	<%
	try{
	int a[] =new int[6];
		for(int i = 0; i<7; i++){
		
		 a[i]=i;
		}	
	}catch(Exception e){
		out.println("Exception:"+e);
		}
	%>
 </BODY>
</HTML>

Output of the Program:

Download this example.

Advertisements

Ads
Share on Google+Share on Google+

ArrayIndexOutOfBoundsException

Posted on: March 12, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: ArrayIndexOutOfBoundsException  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
Deepak
March 27, 2011
ArrayIndexOutOfBoundsException Example

Hi, ArrayIndexOutOfBoundsException occurs if you are accessing the index of an array which is not exists. For example if your array there are 2 items but you are trying to access more than 2 items. Read more at <a href="http://www.roseindia.net/jsp/simple-jsp-example/catching-an-arrayindexoutofbound.shtml">ArrayIndexOutOfBoundsException Example</a>. Thanks

Ads

 

Ads