Why we need Finally with try?
pls expain with ur example..

Answers were Sorted based on User's Feedback



Why we need Finally with try? pls expain with ur example....

Answer / kedar lasane from tuljapur

Because Some Instructions that must be executed in our java
program though there is exception in try block caught by
catch.Once the Exception occurs it catched by catch
statement and control never goes to try block again.So to
Execute some statements after subsequent with try block then
finally {} block is used.Hopefully You find your solution.If
any questions regaurding to java just mail me.
--------------
thnx
my blog: http://www.tuljabhavani.in

Is This Answer Correct ?    34 Yes 4 No

Why we need Finally with try? pls expain with ur example....

Answer / uppaluri

Finally Block always executes when the try block exists. Finally is used for more than exception handling : It allows the Programmer to avoid having cleanup code accidentally bypassed by a return, continue, or break. Putting cleanup code in a finally block is always a good practice. Hopefully you find your Solution.If you have any questions regarding Java mail me

Is This Answer Correct ?    16 Yes 6 No

Why we need Finally with try? pls expain with ur example....

Answer / neha

finally block gets executed in both scenarios I.e exception occurs or doesn't occur..it is used to write the code which we want to execute in both successful or failed scenarios..generally code for cleaning up resources added in finally block.e.g closing file,closing socket connection.

Is This Answer Correct ?    2 Yes 0 No

Post New Answer

More Core Java Interview Questions

What is java used for on a computer?

0 Answers  


Why stringbuilder is not thread safe in java?

0 Answers  


Is intellij better than eclipse?

0 Answers  


String is mutable or immutable?

3 Answers  


Can we write multiple catch blocks under single try block?

0 Answers  






What are aggregate functions explain with examples?

0 Answers  


What is the difference between declaration and definition in java?

0 Answers  


Can we extend singleton class in java?

0 Answers  


public class Base { public void myMethod(int a,intb) {} } // Uses myMethod and then hides it. public class DerivedOne extends Base { private void myMethod(int a,int b); } will this compile or not .yes or no. why

2 Answers  


What is the purpose of premetive data types in java?

2 Answers   Merrill Lynch, TCS,


what are the rules to use try catch finally?

1 Answers   Satyam, UJ,


What is the purpose of file class?

0 Answers  


Categories