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...

what is difference between throw and throws in exception?

Answer Posted / basant

) throws keyword gives a method flexibility of throwing an Exception rather than handling it. with throws keyword in method
signature a method suggesting its caller to prepare for Exception declared in throws clause, specially in case of checked Exception and provide sufficient handling of them. On the other hand throw keyword transfer control of execution to caller by throwing an instance of Exception. throw keyword can also be used in place of return as shown in below example:

private static boolean shutdown() {
throw new UnsupportedOperationException("Not yet implemented");
}

as in below method shutdown should return boolean but having throw in place compiler understand that this method will always throw exception .

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is anagram word?

997


Is an empty arraylist null?

1101


How finally used under exception handling?

948


What is an array in java?

1206


What is singleton class and how can we make a class singleton?

1101


What is complexity in java?

1053


How do you declare an empty string?

1066


How to implement an arraylist in java?

1163


What is length in java?

1019


How many characters is 2 bytes?

996


Difference between java and javascript

1103


What is fail fast in java?

1170


What is runtime polymorphism or dynamic method dispatch?

1016


Is java owned by oracle?

1020


Explain an algorithm to find depth of a binary tree.

1044