Java finally block and throws exception at method level -
in readfilemethod1
, ioexception
explicitly catched before throwing @ method level ensure finally
block executed. however, neccessary catch exception? if remove catch block, shown in readfilemethod2
, finally
block executed well?
private void readfilemethod1() throws ioexception { try { // io stuff } catch (ioexception ex) { throw ex; } { // release resources } } private void readfilemethod2() throws ioexception { try { // io stuff } { // release resources } }
the finally
still gets executed, regardless of whether catch ioexception. if catch block rethrow, not necessary here.
Comments
Post a Comment