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 difference between throw and throws Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "difference between throw and throws" Watch "difference between throw and throws" New topic

difference between throw and throws

Juliana Sasha

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
} catch (NumberFormatException nfEx){
throw new CustomNumberFormatException();
} catch (CustomNumberFormatException){

Jessica Sant

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