• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

exceptions

 
johnathan smith
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey there guys
cheers for the help on my previous topic, was very much appreciated

i have a new problem now which any help would be very much appreciated
my class player takes information such as games played, times dismissed etc

i was wondering would i be able to throw an exception if the number of times dismissed is less than the games played??

my player class code is below
any help would be greatly apprecaited


thanks


[ April 22, 2007: Message edited by: johnathan smith ]
 
Campbell Ritchie
Sheriff
Pie
Posts: 50168
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The short answer is, yes.
The long answer is y-e-e-s.

Show us what you are suggesting. It should be easy enough to implement. At least if you are playing cricket and not baseball . . .
 
Campbell Ritchie
Sheriff
Pie
Posts: 50168
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW: Shouldn't batting average be worked out as a floating-point number? You will have to work out how to get runsScored / timesDismissed as a double return value.
[ April 22, 2007: Message edited by: Campbell Ritchie ]
 
johnathan smith
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i assure you its definately cricket

what im wanting to do is as follows
when creating a Player obviously you enter the details
and if the user enters the more dismissials than the amound of games played (i.e this is impossible) then an excpetion this thrown

any idea how i can do this?
thanks
 
johnathan smith
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...or an error message is printed!

thanks
 
Sidd Kulk
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can provide a check in the Constructor itself and then throw a RuntimeException if the number of dismissals is greater than the number of matches played.

Njoy!!
Sid
 
Campbell Ritchie
Sheriff
Pie
Posts: 50168
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Johnathan Smith, you are quite correct about how to do it, but I would suggest you create your own Exception by inheriting from a suitable Exception class.

You have to provide four constructors which match those in Exception, and don't have to do anything with the methods.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50168
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and surely by numberOfDismissals > numberOfGames you mean


numberOfDismissals > numberOfInningsPlayed
?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic