aspose file tools*
The moose likes Cattle Drive and the fly likes error checking Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "error checking" Watch "error checking" New topic
Author

error checking

Jinny Morris
Ranch Hand

Joined: Apr 29, 2007
Posts: 101
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!
Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1367
    
  18
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?
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9053
    
  12
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.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Jinny Morris
Ranch Hand

Joined: Apr 29, 2007
Posts: 101
Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: error checking