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 the diffrence between a local-tx-datasource and a xa-datasource?
Name three subclasses of the component class?
Explain the difference between object state and behavior?
Is jvm a overhead?
Where can I find seam examples and documentation?
Java is fully object oriented languages or not?
Define prototype?
What does module-relative mean?
What is synchronization and why is it important?
How would you detect a keypress in a jcombobox?
Can we sent objects using Sockets?
Describe activation process?
What you mean by COM and DCOM?
Describe, in general, how java's garbage collector works?
What modifiers may be used with an interface declaration?