Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

What is ioc concept & explain it?

1038


Why do threads block on i/o?

1182


Can I import same package/class twice? Will the jvm load the package twice at runtime?

1085


What are the design considerations while making a choice between using interface and abstract class?

1018


What are the different approaches to represent an inheritance hierarchy?

1019


Which textcomponent method is used to set a textcomponent to the read-only state?

1063


Can I run seam outside of jboss as?

1034


How are the elements of a borderlayout organized?

1050


What is bean? Where can it be used?

1066


How database connectivity in XML is achieved?

2195


What is the difference between the ‘font’ and ‘fontmetrics’ class?

1109


What is the immediate superclass of the applet class?

1029


What is permgen or permanent generation?

968


What is scalable, portability in the view of J2EE?

2475


What is table mutation and how do you avoid it?

2417