This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
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


Win a copy of Building Microservices this week in the Design forum!
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!
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: throw and throws
 
It's not a secret anymore!