Java by API/java.lang/ArrayIndexOutOfBoundsException

Материал из Java эксперт
Перейти к: навигация, поиск

ArrayIndexOutOfBoundsException as a type

   <source lang="java">

/*

* Output:
* 
* array index oob: java.lang.ArrayIndexOutOfBoundsException: 42
*  
*/

public class MainClass {

 public static void main(String args[]) {
   try {
     int c[] = { 1 };
     c[42] = 99;
   } catch (ArrayIndexOutOfBoundsException e) {
     System.out.println("array index oob: " + e);
   } catch (ArithmeticException e) {
     System.out.println("div by 0: " + e);
   }
 }

}

      </source>