UNB/ CS/ David Bremner/ teaching/ java/ ExceptionTest.java
class MidTermException extends Exception{
  private int errcode;

  public MidTermException(int value){
    errcode=value;
  }
  public int getCode(){
    return errcode;
  }
}

public class ExceptionTest {
  
  public static void methodA(int a, int b)
    throws MidTermException { 

    if (a<1){
      throw new MidTermException(b);
    } else {
      methodA(a-1,b*a);
    }

  }
    

  public static int methodB(int a, int b){
    try {
      methodA(a,b);
    }
    catch (MidTermException mte){
      return mte.getCode();
    } 
    return -1;
  }

  public static void main(String[] args){
    
    try {
      methodA(5,1);
      System.out.println(methodB(4,1));
    } 
    catch(MidTermException mte){
      System.out.println(mte.getCode());
    }
    finally{
      System.out.println(methodB(3,1));
    }
    
  }
}
//