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 .


Read more: http://javarevisited.blogspot.com/2012/02/difference-between-throw-and-throws-in.html#ixzz1xaAnuuuu

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why is a constant variable important?

997


What is the difference between instanceof and isinstance?

1126


Explain a few methods of overloading best practices in java?

1019


Do you know how to reverse string in java?

1212


Explain list interface?

995


What is the difference between char and char *?

1145


Can a class be private?

1010


Explain different ways of creating a thread. Which one would you prefer and why?

1101


Is a class subclass of itself?

1126


What makes a function well defined?

1034


Why multiple inheritance is not supported by java?

1025


explain local datetime api in java8?

1055


Which language is java?

1021


Can we override final method?

1068


What is meant by inheritance and what are its advantages?

1162