“finally”块总是在 try-catch 结束时执行,无论是否发生异常。但也总是执行 try-catch 之外和之后的每一行代码。那么,为什么要使用 finally 语句呢?
例子:
try {
//code...
} catch (Exception e) {
//code...
} finally {
System.out.println("This line is always printed");
}
System.out.println("Also this line is always printed !! So why to use 'finally'?? ");