the use of try and ffinally keyword



the use of try and ffinally keyword..

Answer / xavier

try and finally are keywords associated with exception
handling(run time errors)
try block provides two benefits it allows you to fix the error.
it prevents program from automatically terminating
e.g.
class Exception_handling
{
public static void main(String args[]){
try{
int d=0;
int x= 42/d;
System.out.println("this will not be printed");
}
catch(Exception e)(
System.out.println("this will be printed");
}
}
}
you might observe that in above code the line after int
x=42/d is not printed but there are certain operations that
you need to perform before proceeding further and finally
would serve this purpose

class Exception_handling
{
public static void main(String args[]){
try{
int d=0;
int x= 42/d;
System.out.println("this will not be printed");
}
catch(Exception e)(
System.out.println("this will be printed");
}
finally{
system.out.println("this will be printed");
}
}
}

Is This Answer Correct ?    10 Yes 0 No

Post New Answer

More Advanced Java Interview Questions

Explain bind(), rebind(), unbind() and lookup() methods?

1 Answers  


Why won’t the jvm terminate when I close all the application windows?

1 Answers  


How many layers are there in RMI and what are they?

1 Answers  


Different between Struts and Spring? or Why use Spring, if you are already using Struts?

3 Answers   HP,


What is abstract schema?

1 Answers  


When a thread terminates its processing, it enters into what state?

1 Answers  


How many JSP scripting elements and what are they?

4 Answers   TCS,


What are the pros and cons of detached objects?

1 Answers  


Difference between sleep and suspend?

3 Answers  


In HashTable I am storing null value..then what is the error it will show

2 Answers   GM General Motors,


What is checkpoint? How to create checkpoints in our java projects?

1 Answers   ABC,


What is Remote Interface?

1 Answers  


Categories