File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes difference between throw and throws Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "difference between throw and throws" Watch "difference between throw and throws" New topic
Author

difference between throw and throws

Juliana Sasha
Greenhorn

Joined: Oct 07, 2003
Posts: 5
What is the exact diffence between the two.
Again I would appreciate an example to diffentiate the two.
Chris Brat
Ranch Hand

Joined: May 22, 2003
Posts: 108
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){
}


SCJP 1.2, SCJP 5, SCBCD
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: difference between throw and throws