It's not a secret anymore!
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

throw and throws

Jello Yao

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

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

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

Joined: Jan 05, 2003
Posts: 28
"throws" is just like try-catch statement
Excepiton may happen
"throw" means that the exception throws
----------------------------- IDE tool : JawaBeginer
2.Java Jar tool : JavaJar
Jello Yao

Joined: Jan 05, 2003
Posts: 13
Thanks for the help!
I agree. Here's the link:
subject: throw and throws
It's not a secret anymore!