import java.io.*;
class MyBaseException extends Exception {
	public MyBaseException(){
		super();
	}
	public MyBaseException(String s){
		super(s);
	}
}
class MySubException extends MyBaseException{
	public MySubException(){
		super();
	}
	public MySubException(String s){
		super(s);
	}
}
class ExceptionDemo {
	public static void method1(int i) {
		try{
			method2(i);
		}
		catch(MyBaseException e){
			System.out.println("MyBaseException: ");
			System.out.println(e.getMessage());
			System.out.println("Handled in method1");
		}
	}
	public static void method2(int i) throws MyBaseException {
		int result;
		try{
			System.out.println("i=  "+i+"\n");
			result=method3(i);
			System.out.println("method3(i) = "+result);
		}
		catch(MySubException e){
			System.out.println("MySubException: ");
			System.out.println("Handled in method2");
		}
		finally{
			System.out.println("\n");
		}
	}
	public static int method3(int i) throws MyBaseException,MySubException{
		if (i==0) throw new MyBaseException("Value assigned is too less");
		else if (i==99) throw new MySubException("Value assigned is too high");
		else return i+i; 
	}
	public static void main(String[] args) {
		try{
			method1(99);
			method2(99);
			method3(99);
		}
		catch(Exception e){}
	}
}
