• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to handle exceptions?  RSS feed

 
Rick Horn
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am learning so please bear with me.

I'm working on this program for exception handling.

The program asks the user for a number between 1-100. If the number is within that range it simply prints it out. If the number is too high, too low, or a negative it throws an error message. Each exception of too high, too low, neg, should be a separate class that the driver program checks. I also need a "verify" class that checks the number entered is within the range by use of a constructor that has two int parameters, first int is low range of 1 and second int is high number of 100.

This is what I have so far...please don't be too harsh I'm new at this...what I don't understand is how the highlow class "calls" the error checking and basically what needs to be defined in those classes...any help is greatly appreciated!

 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are several things wrong in this programme. Please see this for your reference and correct the programme accordingly.

Right now your code can't compile. You can check the mentioned tutorials for right usage.
 
Campbell Ritchie
Marshal
Posts: 56587
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Start by going through the Java® Tutorials. The hard part of handling Exceptions is working out two things:-
  • 1: Where is it best to handle this Exception?
  • 2: What is the best action to take if this Exception occurs?
  •  
    Campbell Ritchie
    Marshal
    Posts: 56587
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I see I have given you the same link that Tushar Goel has already given you.
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!