This week's book giveaway is in the Java in General forum.
We're giving away four copies of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 and have ishori Sharan & Adam L Davis on-line!
See this thread for details.
Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic