Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Checking method parameters for validity

 
Seid Myadiyev
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do I need to check method parameters for validity, like I would in my other projects?
For example:
- throw application exception (or IllegalArgumentException) when criteria is null
- throw IllegalArgumentException when recNo is less than 0 or greater than total number of records in db, instead of RecordNotFoundException
It seems to me that it is not necessary for this particular project but I just want to confirm!
Thank you!
Seid
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would say that you need to enforce parameter values. The probject (hypothetically) will be maintained by some imaginary company for quite a while, changes being made, etc ... One day some silly junior programmer will try and do something that you didn't originally design it to. And since you didn't enforce those parameters, BOOM!
Yes, you are the only one developing the software now, and really it is that way forever. But play along. Do a good job of throwing those RuntimeExceptions and make your grader feel good about himself.
 
Vlad Rabkin
Ranch Hand
Posts: 555
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Seid
- throw application exception (or IllegalArgumentException) when criteria is null

Perfect idea!
- throw IllegalArgumentException when recNo is less than 0 or greater than total number of records in db, instead of RecordNotFoundException

I personally would preffer to throw RecordNotFoundException not to risk to breach the specification requirements. Howevers, I think IllegalArgumentException is also a valid solution and should be Ok.
Best,
Vlad
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic