• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Checking method parameters for validity

 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 555
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Note to self: don't get into a fist fight with a cactus. Command this tiny ad to do it:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic