/** * Input: 8, 3, 11, -4, 6, -7, 2, 0 */ class Example2 { public static void main(String[] args) { int i; int tmp; /* iterate through the argument vector */ for (i = 0; i < args.length; i++) { try { tmp = Integer.parseInt(args[i]); if (tmp < 0) { throw (new MyException("less than zero")); } System.out.println(tmp); } catch (MyException e) { System.out.println("Exception caught ..."); System.out.println(e.getMessage()); } } System.out.println("done."); } } class MyException extends Exception { MyException(String text) { super(text); } }