• 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

How to handle exceptions?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!

 
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79179
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I see I have given you the same link that Tushar Goel has already given you.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic