What is 'finally' method in Exceptions?

Answers were Sorted based on User's Feedback



What is 'finally' method in Exceptions?..

Answer / guest

this method will execute in any case whether an exeption
is aughat or not

Is This Answer Correct ?    3 Yes 0 No

What is 'finally' method in Exceptions?..

Answer / sumesh babu r

The finally method will be executed after a try or catch
execution.
It is mainly used to free up resources.
The codes that must be executed, irrespective of whether the
exception is occurred or not, will be included in the
finally block.

See the following simple example to demonstrate the syntax
public class FinallyExample
{

public static void main(String args[])
{

try
{
// the code that may cause an exception
}
catch (Exception e)
{
// the code to be executed, when the exception
occurs
}
finally
{
// code to be executed irrespective of the
occurrence of exception
}
}
}

When using finally, the catch block is not mandatory.
ie, a try block must be followed by a catch or finally block.

Is This Answer Correct ?    3 Yes 0 No

What is 'finally' method in Exceptions?..

Answer / ravikiran(aptech mumbai)

finally method is used to conserve the resources before the
exception is being caught

Is This Answer Correct ?    1 Yes 1 No

What is 'finally' method in Exceptions?..

Answer / k.k

ALL ANSWERS GIVEN ABOVE ARE WRITE.........


BUT

ONLY CASE THAT CAN SUPPRESS THE FINALY BLOCK IS

public class SupressFinallyExample
{

public static void main(String args[])
{

try
{
// the code that may cause an exception
//System.exit(0);
}
catch (Exception e)
{
System.exit(0);//if exception occure..
}
finally
{
// code to be executed irrespective of the
occurrence of exception
}
}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

What is the difference between length and length() method in java?

0 Answers  


If I will write String s=new String("XYZ"); String s1=new String("XYZ"); if(s.equals(s1)){ sop("True"); } else{ sop("False"); } This program will give me "True". But When I am creating my own class suppose class Employee{ public Employee(String name); } Employee e= new Employee("XYZ"); Employee e1 = neew Employee("XYZ"); if(e.equals(e1)){ sop("True"); } else{ sop("False"); } Then it will give the output as "False". Can I know what is happening internally?

5 Answers  


What is the difference between an argument and a parameter?

0 Answers  


What is numel matlab?

0 Answers  


What is a marker interface?

0 Answers  






What are three types of loops in java?

0 Answers  


Define Compiling?

3 Answers  


what is server side caching?

0 Answers   AIG,


Is java call by value?

0 Answers  


relation between list and linked list

1 Answers   Infosys,


What is the use of Getters and Setters method ?

4 Answers  


When will you define a method as static in Java?

0 Answers   SwanSoft Technologies,


Categories