无论内部最终块是什么(几乎)始终执行,那么将代码封装到其中或将其保持未封闭之间的区别是什么?
据我所知,以下两个代码片段都将起到同样的作用.为什么要有finally块?
代码A:
try { /* Some code */ }
catch { /* Exception handling code */ }
finally { /* Cleanup code */ }
Run Code Online (Sandbox Code Playgroud)
代码B:
try { /* Some code */ }
catch { /* Exception handling code */ }
// Cleanup code
Run Code Online (Sandbox Code Playgroud)