This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between Throws and Throw

 
satya sahu
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
 
Paul Sturrock
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.
 
Brian Pipa
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