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

What is difference RMI registry and OSAgent?

1 Answers  


Why do I get a duplicate name error when loading a jar file?

0 Answers  


What is the use of Semaphore?

3 Answers  


What’s jboss jbpm?

0 Answers  


Difference between sleep and suspend?

3 Answers  


What are various types of class loaders used by jvm?

0 Answers  


Explain RMI Architecture?

0 Answers  


Which javutil classes and interfaces support event handling?

0 Answers  


how to search the pertical objects in a Collections

3 Answers   iGate,


what is domain,give me some brief information about that?

1 Answers  


What is resource bundle?

1 Answers  


Do you think that java should have had pointers?

0 Answers  


Categories