This week's book giveaway is in the OCP forum.
We're giving away four copies of OCP Java SE 8 Programmer II Exam Study Guide and have Kathy Sierra, Bert Bates, & Elizabeth Robson on-line!
See this thread for details.
Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Difference between Throws and Throw  RSS feed

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, can somebody tell me the difference between throws and throw with some good example.
Thanks in advance.

satya
 
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"throws": used to announce a method may throw an exception, so you need to handle it in code that uses the method.
"throw": actually throws an exception.
 
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
throws say it might throw sometime in the future
throw does the throwing NOW

Brian
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!