• 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

error checking

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been told that we don't need to worry about exception handling in the very first "java in general" exercises, but I'm somewhat confused - or I've confused myself or something. Does this mean that until told otherwise we should assume that the user did everything right? Meaning, for example, that in Java-4a I should assume that the user entered exactly one integer between 0 and 99 along with the program name and just trek along?

Thanks!
 
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, exception handling is one thing - error checking is another.
You can do quite simple checks for range without going ahead and throwing exceptions (which changes the flow of the program pretty considerably).

On the other hand, the assignment doesn't specify that you need to make sure that the input is clean. At this particular point in time, if the user puts in their dog's first name rather than an integer, the program can crash and burn in all its glory.

- does this just about cover it, Marilyn?
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jinny Morris:
I've been told that we don't need to worry about exception handling in the very first "java in general" exercises, but I'm somewhat confused - or I've confused myself or something. Does this mean that until told otherwise we should assume that the user did everything right? Meaning, for example, that in Java-4a I should assume that the user entered exactly one integer between 0 and 99 along with the program name and just trek along?



You don't need to worry about exception handling such as the case where the user passes in "ab" instead of "12", which would throw an Exception trying to parse "ab" as a number. You do, however, need to handle range checking as the assignment says. You can do that without using exceptions.

Try thinking along the lines of the way the instructor solutions handle checking whether user input exists or not without handling the NullPointerException that could be thrown if the user doesn't provide an argument.
 
Jinny Morris
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!
reply
    Bookmark Topic Watch Topic
  • New Topic