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

What is integers and example?

987


why we use merge option in hybernate pls give a ex snippet

1995


Why parsing is done?

977


How many ways can we create singleton class?

966


Which variables are stored in heap?

1026


Is java type safe?

958


Can a final variable be initialized in constructor?

969


What does int argc char * argv [] mean?

993


Can you override private or static method in java?

973


Why java is called not pure object oriented language?

1017


why not override thread to make a runnable? : Java thread

1000


What initialize variables?

1020


What is the lifetime and scope of a variable?

1013


Can we synchronize static methods in java?

1100


Is singleton set an interval?

962