Organizational Research By

Surprising Reserch Topic

Question:Does the code in finally block get executed if there is an exception and a return statement in a catch block?


The finally clause is used to provide the capability to execute code no matter whether or not an exception is thrown or caught. If an exception occurs and there is a return statement in catch block, the finally block is still executed. The finally block will not be executed when the System.exit(0) statement is executed earlier or on system shut down earlier or the memory is used up earlier before the thread goes to finally block.

try{
//some statements
}
catch{
//statements when exception is caught
}
finally{
//statements executed whether exception occurs or not
}

asked Sep 13, 2013 in Core java by ashish singh
edited Sep 12, 2013
0 votes
27 views



Related Hot Questions



Government Jobs Opening


...