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 are local interfaces? Describe.

0 Answers  


How can a dead thread be restarted?

1 Answers   IBM, Wipro,


How many JSP scripting elements and what are they?

4 Answers   TCS,


what is activation monitor and what is its job?

1 Answers  


If I define a method in JSP scriplet <%..%>, where will it go after translation into a servlet?

8 Answers   HeadStrong,






the same information whether it will connect to the database or it will be used previous information?

0 Answers  


What is metaspace?

0 Answers  


What method is invoked to cause an object to begin executing as a separate thread?

0 Answers  


What is the difference between static and non-static with examples?

0 Answers   HCL,


What are the steps to write p-to-p model application?

0 Answers  


When is the best time to validate input?

0 Answers  


What are the steps involved in developing an RMI object?

1 Answers  


Categories