Q:

Java exception handling

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");
    }
}
}

A:

Compiler doesn't/can't know that at runtime no exception will be throwed by fn2() since it's declared that it may throw an Exception, that's why you got an error.

A:

Remove the throws Exception from fn2() signature

