Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

throws & throw ??

 
dlc
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic