In Java, Finally generally appears in the Try {} structure, used to store the statement to be executed in the TRY structure, such as
String s = "1";
Try {
s = "2";
System.out.println (s);
IF (s == "2")
Throw New Exception ("H");
} catch (exception e) {
s = "3";
System.out.println (s);
} finally {
s = "4";
System.out.println (s);
}
s = "5";
System.out.println (s);
The result of the output is 2, 3, 4, 5 (here the comma only is shown). The above statement is very clear, but in the above structure, it is more complicated, such as
String s = "1";
Try {
s = "2";
System.out.println (s);
Return;
} catch (exception e) {
s = "3";
System.out.println (s);
} finally {
s = "4";
System.out.println (s);
}
s = "5";
System.out.println (s);
The result of the output is 2, 4
That is to say in the TRY structure, although the RETURN statement is used to force the function to return, it is no longer executed down, but it is still implemented in FINALLY. However, in addition to other statements outside FINALLY are no longer being performed.