File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes throw and throws Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "throw and throws" Watch "throw and throws" New topic
Author

throw and throws

Jello Yao
Greenhorn

Joined: Jan 05, 2003
Posts: 13
Does the only difference between using throw and throws is the English grammer?
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
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();


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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".


"I'm not back." - Bill Harding, Twister
Robbie shi
Greenhorn

Joined: Jan 05, 2003
Posts: 28
"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

Joined: Jan 05, 2003
Posts: 13
Thanks for the help!
 
wood burning stoves
 
subject: throw and throws
 
Similar Threads
throw throws
diff b/w Throw and Throws
Difference
throws and throw
Throws and throw