aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes what's the difference between Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "what Watch "what New topic
Author

what's the difference between "throw" and "throws"?

richard peng
Greenhorn

Joined: Nov 04, 2004
Posts: 1
In jave error handling, there are two keywords: throw and throws. What't the difference between them?
Vipin Das
Ranch Hand

Joined: Jul 05, 2004
Posts: 47
"throws" is used to specify that a method is capable of throwing an exception and "throw" is used to throw an Exception explicitly. Please refer thisarticle
Netty poestel
Ranch Hand

Joined: Sep 20, 2004
Posts: 131
Hi..

take this one:-

public static long method(int x) throws IllegalArgumentException {
if (x>=table.length) throw new IllegalArgumentException("overflow; xis too large");
if(x<0) throw new IllegalArgumentException("x must be non-negative");

So this is how I see it. The 'throw(s)' is the more generic one declared first...
then follow the siblings(ducklings).. 'throw'

My 2 cents
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what's the difference between "throw" and "throws"?