Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

throw and throws

 
Jello Yao
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the only difference between using throw and throws is the English grammer?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, "throws" is used in method declarations, as in
void foo() throws SomeException {}
whereas "throw" is used to actually do throw an Exception, as in
throw new SomeException();
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I.e. "throws" is just a warning, meaning "this method may throw the following exception". While "throw" is a command - "throw an exception right now".
 
Robbie shi
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"throws" is just like try-catch statement
Excepiton may happen
"throw" means that the exception throws
--
Robbies
-----------------------------
1.java IDE tool : JawaBeginer
2.Java Jar tool : JavaJar
http://www.pivotonic.com
 
Jello Yao
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic