File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes throws & throw  ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "throws & throw  ??" Watch "throws & throw  ??" New topic
Author

throws & throw ??

dlc
Greenhorn

Joined: Feb 17, 2004
Posts: 3
How to distinguish the practical urage between [throws] and [throw]?
And in what way can they be applied to?
thanks a lot

A:0,1,1,0 BUT,WHY???
David Peterson
author
Ranch Hand

Joined: Oct 14, 2001
Posts: 154
It will help you a lot to understand the code if you format it neatly with proper indentation...


You can now see that the throws clause is part of the method declaration, whereas the throw statement is part of the method body.

The throws clause tells you what exceptions the method may throw. The person calling the method must either handle these exceptions (with a try..catch) or declare them in its own throws clause (which will pass the exception up the call-stack until something handles it, or the application crashes).
The throw statement actually throws an exception.
[ May 09, 2004: Message edited by: David Peterson ]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
dlc,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: throws & throw ??