• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

difference between throw and throws

 
Juliana Sasha
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the exact diffence between the two.
Again I would appreciate an example to diffentiate the two.
 
Chris Brat
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
throws used in a method declaration etc, to declare the possible exceptions that can be thrown by the method.
void method() throws Exception {
}

throw used to actually do the throwing
try{
...
...
} catch (NumberFormatException nfEx){
throw new CustomNumberFormatException();
} catch (CustomNumberFormatException){
}
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
throw and throws are very important parts of Java's Exception Handling functionality.
To get the best bang for your buck, I'd suggest checking out this Sun Tutorial: Lesson: Handling Errors with Exceptions
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic