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 Hash Code in Java?

6 Answers   Cognizant,


How to sort the elements in HashMap

3 Answers   Ness Technologies,


How many characters is 16 bytes?

0 Answers  


What are the types of java languages?

0 Answers  


What is an example of declaration?

0 Answers  






what is unreachable code problem in multiple catch statements

3 Answers  


What is javac used for?

0 Answers  


What is size_t?

0 Answers  


Hi Every One I Have Small Doubt Please answer This???????????????????????????? I Want to use AbstractList class methods(java.util.AbstractList) My Program is import java.util.*; class DemoOne extends AbstractList { public static void main(String[] args) { AbstractList a=new DemoOne();//This One is Correct?? DemoOne a1=new DemoOne();//This One is Correct?? Both Are Not Working System.out.println("Hello World!"+a); System.out.println("Hello World!"+a1); } } Error IS: DemoOne.java:2: DemoOne is not abstract and does not override abstract method get(int) in java.util.AbstractList class DemoOne extends AbstractList AnyOne can Please Provide The Solution????????????????????????? Plzzzzzzz

3 Answers  


What are the two types of exceptions in java? Which are the differences between them?

0 Answers  


how to compile jsp?

4 Answers   Logica CMG,


In java, how we can disallow serialization of variables?

0 Answers  


Categories