File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
richard peng
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In jave error handling, there are two keywords: throw and throws. What't the difference between them?
 
Vipin Das
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 131
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic