• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

throws clause doubt in exception handling ?

 
siva chaitanya
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
throws clause throws the exception to where and how ? and also please explain difference between throws and throw ?

Thanks in advance
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please go through the Oracle tutorials on Exceptions - Throwing Exceptions

Do please SearchFirst. This question about Exceptions has been asked a lot many times.
 
siva chaitanya
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
throw new userdefinedexception(); is this valid? Can we give any names for an exception using throw keyword.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
siva chaitanya wrote:throw new userdefinedexception(); is this valid? Can we give any names for an exception using throw keyword.


What happened when you tried it?
 
siva chaitanya
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i got it jeff we can give eny names by extending Exception class
 
Campbell Ritchie
Sheriff
Posts: 48386
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But your names should conform to standard naming conventions, example here, and end with Exception. If you want to throw an Exception because an empty String has been passed, it should be called EmptyStringException. You should also go through the hierarchy of Exceptions, because there might be a better superclass than Exception.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic