What is 'finally' method in Exceptions?
Answers were Sorted based on User's Feedback
Answer / guest
this method will execute in any case whether an exeption
is aughat or not
| Is This Answer Correct ? | 3 Yes | 0 No |
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 |
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 |
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 |
why Runnable interface is preferable than extending the Thread class?
7 Answers Aizza, College School Exams Tests, Sybrant Technologies, Wipro,
Can a top level class be private or protected?
What best practices should you follow while writing multithreaded code in java?
HOW TO PRINT A NO IN WORDS USING WHILE LOOP THE NO WILL BE PRINTED WHEN IT WILL BE IN THE RANGE BETWEEN 1 AND 3?
How do you read and print a string in java?
What is parameter example?
Explain about global variables in Java?
What if static is removed from main method?
Which number is denoted by leading 0x or 0x in java?
How to perform selection sort in java?
What happens when you assigned a 'double' value to a 'String'?
Can list be null in java?