import java.util.*; public class MyException { public static int average(String[] seq) throws BadElementException { int sum = 0; for (int i = 0; i < seq.length; i++){ try { sum += Integer.parseInt(seq[i]); } catch (Exception e) { throw new BadElementException("Element is not a number", i); } } return sum / seq.length; } public static void main(String[] args) { try { System.out.println(average(args)); } catch (BadElementException e) { System.out.println("Oops, " + args[e.getIndex()] + " isn't a number"); } } } class BadElementException extends Exception { private int index; public BadElementException(String message, int index) { super(message); this.index = index; } public int getIndex() { return index; } }