Win a copy of Serverless Applications with Node.js this week in the NodeJS 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

LocalDate and illegalArgumentExeption  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I have a question about using LocalDate to check if someone is too old.
If they are too old I would like to throw an exception but it is not working. Here is my code



and


Thank you for you help.
 
Saloon Keeper
Posts: 9997
208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

ItDoesntWorkIsUseless. The next time, please explain what output you were expecting and what you got instead.

Regardless, the cause of your issue is that you're checking for the difference of 100 twice. In getAge(), you return 0 if the difference is greater than 100 years. You then compare 0 to 100 a second time, which is never true, so the exception is never thrown.
 
Ryan Isaacson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I tired what you said and changed my code. What I want is to have the main class say too old cannot be over 100 with the illegal argument exception.
This is my current code


I need the actual output to meet the expected output.
Expected output: java.lang.IllegalArgumentException: Please check the year entered, student cannot be over 100 years old
Actual output:  
my actual output is blank...
Thank you
 
Stephan van Hulst
Saloon Keeper
Posts: 9997
208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please include the method that calls setBirthday()? We'd like to see how you're testing your code.
 
Does this tiny ad smell okay to you?
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!