/**
* @author lautturi.com
* Java example: java try catch
*/
import java.util.*;
public class Lautturi {
public static void main(String[] args) {
try {
int[] myNumbers = { 1, 2, 3, 4, 5, 6 };
System.out.println(myNumbers[6]);
} catch (Exception e) {
System.out.println(e.getMessage());
// e.printStackTrace();
}
}
}
output:
Index 6 out of bounds for length 6 java.lang.ArrayIndexOutOfBoundsException: Index 6 out of bounds for length 6 at hello.Lautturi.main(Lautturi.java:81)