作为这方面的新手,finally
在异常处理中使用该子句有什么好处.或者换句话说,当最好使用它时,最好不要使用它.
我能想到的唯一一个是关闭输入/输出流......任何其他好处??? !!
该finally
是非常在其中一些资源需要被释放的情况下非常有用.
例如:
InputStream is = null; try { is = new FileInputStream("C://test.txt"); //some reading-file logic } catch (Exception e) { //exception handling } finally { //releasing the resources (closing the input stream) if (is != null) { is.close(); } }