Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

difference between throw and throws

 
priyanaka jaiswal
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

What is difference between throws and throw?

Thanks in advance
 
Vijay Tidake
Ranch Hand
Posts: 148
Hibernate Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

throws is used in method declaration,which may throw a exception(Checked or Unchecked)

throw is used to throw an Exception from a code.

for ex



Thanks
 
akhter wahab
Ranch Hand
Posts: 151
Java MyEclipse IDE Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
priyanaka jaiswal wrote:Hi all,

What is difference between throws and throw?

Thanks in advance


check this link webpage
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
throws-used with method declaration indicates that the method may throw that type of exception
throw-used to throw an exception object
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vijay Tidake wrote:
throws is used in method declaration,which may throw a exception(Checked or Unchecked)

dont *throws* unchecked exception with method declaration, it become meaningless . because it wont intimate about exception to other programmer who will use your method!
 
fred rosenberger
lowercase baba
Bartender
Posts: 12145
30
Chrome Java Linux
  • Likes 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If i said "Throw the ball", I'm telling <someone> do do something.

If i said "Fred throws a fastball", I am describing something Fred can do.

-------

You use "throw" to tell the jvm that an exception should be thrown. You use "throws" to describe what a method can do.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic