the use of try and ffinally keyword

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


Please Help Members By Posting Answers For Below Questions

To identify IDL language what mapping mechanism is used?

3406


What’s jboss jbpm?

570


What are the purpose of introspection?

669


what are the activation groupworks?

1667


Explain about RMI Architecture?

601






Explain the advantages and disadvantages of detached objects.

568


Difference between hashmap and hashtable?

598


How are commas used in the intialization and iteration parts of a for statement?

573


Can you control when passivation occurs?

589


What are the diff types of exception?

546


What are the difference between RMI and CORBA?

615


How are the elements of a borderlayout organized?

587


what are getters and setters in Java with examples?

1276


How can I avoid validating a form before data is entered?

543


whats is mean by tiles in struts

1609