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
How primary key is implemented in Oracle?
What class is the top of the awt event hierarchy?
What is the argument type of a programs main() method?
What is the map interface?
What is a session? Can you share a session object between different theads?
AS a developer will u create a data source in connection pool? If so how will u do that, how to access the object from connection pool using IRAD tool?
What do you know about seam?
What is the difference between java class and bean?
Where can I ask questions and make suggestions about seam?
Name three subclasses of the component class?
What are local interfaces? Describe.
What are transaction attributes?
What is the difference between the string and stringbuffer classes?
Can I have an action without a form?
Whats new with the stop(), suspend() and resume() methods in jdk 1.2?