public class Demo4 { public static void main(String[] args) { int[] a = new int[10]; // Index out of range try { if ( Math.random() < 0.5 ) a = null; // 50% chance a gets null... a[99] = 1; } catch (Exception e) // General exception first --> error { System.out.println("(2)" + e); System.out.println("DONE"); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("(1)" + e); System.out.println("DONE"); } } }