File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "what Watch "what New topic

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

richard peng

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

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:
subject: what's the difference between "throw" and "throws"?
It's not a secret anymore!