java - Can we use "return" in finally block -
this question has answer here:
- returning block in java 5 answers
- multiple returns: 1 sets final return value? 6 answers
can use return statement in finally block. can cause problem?
returning inside finally
block cause exceptions
lost.
a return statement inside block cause exception might thrown in try or catch block discarded.
according java language specification:
if execution of try block completes abruptly other reason r, block executed, , there choice:
if block completes normally, try statement completes abruptly reason r. if block completes abruptly reason s, try statement completes abruptly reason s (and reason r discarded).
note: per jls 14.17 - return statement completes abruptly.
Comments
Post a Comment