Answer Posted / 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 View All Answers
What is ioc concept & explain it?
Why do threads block on i/o?
Can I import same package/class twice? Will the jvm load the package twice at runtime?
What are the design considerations while making a choice between using interface and abstract class?
What are the different approaches to represent an inheritance hierarchy?
Which textcomponent method is used to set a textcomponent to the read-only state?
Can I run seam outside of jboss as?
How are the elements of a borderlayout organized?
What is bean? Where can it be used?
How database connectivity in XML is achieved?
What is the difference between the ‘font’ and ‘fontmetrics’ class?
What is the immediate superclass of the applet class?
What is permgen or permanent generation?
What is scalable, portability in the view of J2EE?
What is table mutation and how do you avoid it?