I know that the value returned from final block always overwrite whatever is returned, but is it supposed to overwrite or suppress a thrown exception?
public static String callme() throws Exception {
try {
throw new Exception();
} catch (Exception e) {
System.out.println("inside the catch block");
throw e;
} finally {
System.out.println("Inside finally");
return "returned from finally";
}
}
public static void main(String[] args) {
try {
System.out.println(callme());
} catch (Exception e) {
System.out.println("something is caught");
}
}
expected output -
inside the catch block
Inside finally
returned from finally
something is caught
reality -
inside the catch block
Inside finally
returned from finally
I wanna ask
why this is happening?
if its happening then isn't it bad, because the calling method won't know the exception thrown