try { ArrayList<String> list = new ArrayList<String>(); String s = list.get(18); } catch (IndexOutOfBoundsException e) { String s = e.getClass().toString(); //this System.out.println(e);