java - Can we use "return" in finally block -


this question has answer here:

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

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -