I have the following code. In that fn2 is actually throwing an exception and it is caught in the function itself. In the function fn1 the compiler is complaining about unhandled exception since fn2 is declared to be throwing an Exception.
Why it is so? Since the exception is caught inside fn2 it shouldn't be complaining right?
Please explain the behavior.
public class ExepTest {
/**
* @param args
*/
public static void main(String[] args) {
ExepTest exT = new ExepTest();
exT.fn1();
}
public void fn1(){
fn2();//compilation error
}
public void fn2() throws Exception{
try{
throw new Exception();
}
catch(Exception ex){
System.out.println("Exception caught");
}
}
}