The Java Program: Recurse.java

  1 public class Recurse {
  2 
  3    /*
  4    class Zero extends Exception {};
  5    static Zero z = new Zero ();
  6    */
  7 
  8    public static void p (final int n) throws Exception {
  9       class Zero extends Exception {final int x=n;};
 10       System.out.println (Zero.class);
 11       try {
 12          if (n>0) {
 13             p (n-1);
 14          } else {
 15             throw new Zero();
 16          }
 17       } catch (Zero e) {
 18          System.out.println ("Exception 'Zero'");
 19          throw e;
 20       } catch (Exception e) {
 21          System.out.println ("Some other exception");
 22          throw e;
 23       }
 24    }
 25     
 26    public static void main (String argv[]) {
 27       try {
 28          p (5);
 29       } catch (Exception e) {
 30          System.out.println ("Giving up");
 31       }
 32    }
 33 }