/** * Input: 8, 3, -11, -4, 5, -2, 6 */ class Example5 { public static void main(String[] args) { int i; int tmp; int count = 0; try { /* iterate through the argument vector */ for (i = 0; i < args.length; i++) { try { tmp = Integer.parseInt(args[i]); if (tmp < 0) { throw (new MyException1("less than zero")); } System.out.println(tmp); } catch (MyException1 e) { System.out.println("Exception1 caught ..."); System.out.println(e.getMessage()); count++; if (count >= 3) { throw (new MyException2()); } } finally { System.out.println("Processed one integer"); } } } catch (MyException2 e) { System.out.println("Exception2 caught"); System.out.println("Enough."); } finally { System.out.println("done."); } } } class MyException1 extends Exception { MyException1(String text) { super(text); } } class MyException2 extends Exception { }