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 the difference between ear, jar and war file?

0 Answers  


does j2ee means advanced java

10 Answers  


What is the relation between the infobus and rmi?

0 Answers  


what is handle?

0 Answers  


What is private static final long serialVersionUID = 1L;

3 Answers   Google,






what is default length of textfield ?

1 Answers  


What is RMI and what are the services in RMI?

0 Answers  


which type of objects reference will be given to client?

0 Answers  


What value does read() return when it has reached the end of a file?

0 Answers  


Difference between swing and awt?

0 Answers  


Is the session factory thread safe?

0 Answers  


java is fully object oriented languages or not? why?

12 Answers   HCL,


Categories