If we give return statement like this in try, what will be the order of execution
try{
--- ----
-----
return a;
}
catch{
}
finally{
}
Here what will be order of execution if there is return in try. Please let me know
finally defines a block of code we use along with the try keyword. It defines code that's always run after the try and any catch block, before the method is completed. The finally block executes regardless of whether an exception is thrown or caught.
The finally block always executes when the try block exits. This ensures that the finally block is executed even if an unexpected exception occurs.
A finally block always executes, regardless of whether an exception is thrown. The following code example uses a try / catch block to catch an ArgumentOutOfRangeException.
Java try block It must be used within the method. If an exception occurs at the particular statement in the try block, the rest of the block code will not execute. So, it is recommended not to keep the code in try block that will not throw an exception. Java try block must be followed by either catch or finally block.
http://docs.oracle.com/javase/tutorial/essential/exceptions/finally.html
http://docs.oracle.com/javase/specs/jls/se7/html/jls-14.html#jls-14.20.2
finally
always executes. If there is a return
in try
, the rest of try
and catch
don't execute, then finally
executes (from innermost to outermost), then the function exits.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With