java try catch example

java try catch example
‮ot refer‬:lautturi.com
/**
 * @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)
Created Time:2017-10-01 00:20:02  Author:lautturi