Home Jsp Simple-jsp-example ArrayIndexOutOfBoundsException

Related Tutorials


 
 

Share on Google+Share on Google+

ArrayIndexOutOfBoundsException

Advertisement
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.

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.

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: March 12, 2008

Related Tutorials

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
DMCA.com