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 do you know about seam?
What is a session? Can you share a session object between different theads?
what is meant by JRMP?
What are local interfaces? Describe.
What are the pros and cons of detached objects?
Which are the different segments of memory?
What are JTA/JTS and how they used by client?
How are the elements of a borderlayout organized?
What is a modular application? What does module-relative mean?
What is aop(assepct oriented programing)?
Explain about local interfaces.
What are the sequence of steps to write pub or sub model kind of application?
What is JTS?
Which component handles cluster communication in jboss?
What value does readline() return when it has reached the end of a file?