ArrayIndexOutOfBoundsException
KW.java
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW Array Length: 6 First Element: Mango Last Element: StrawberryException in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 6 out of bounds for length 6 at KW.main(KW.java:10) kodingwindow@kw:~$
Java program to handle the ArrayIndexOutOfBoundsException
KW.java
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW Array Length: 6 First Element: Mango Last Element: Strawberry Requested element not found kodingwindow@kw:~$
Java program to display exception throwable details using the printStackTrace() method
KW.java
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW Array Length: 6 First Element: Mango Last Element: Strawberry Requested element not found java.lang.ArrayIndexOutOfBoundsException: Index 6 out of bounds for length 6 at KW.main(KW.java:12) java.lang.ArrayIndexOutOfBoundsException: Index 6 out of bounds for length 6 kodingwindow@kw:~$
What Next?
Java program to handle the NegativeArraySizeException
Java program to handle the OutOfMemoryError exception
Java program to handle divide by zero exception
Advertisement