Why return is not honoring the value of variable in finally block? [duplicate]
问题 This question already has answers here : When finally is executed? [duplicate] (10 answers) Closed 3 months ago . finally always gets executed last, so the statement x = 3 should be executed last. But, when running this code, the value returned is 2. Why? class Test { public static void main (String[] args) { System.out.println(fina()); } public static int fina() { int x = 0; try { x = 1; int a = 10/0; } catch (Exception e) { x = 2; return x; } finally { x = 3; } return x; } } 回答1: That's