• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adding Exception error problems

 
jon ladd
Ranch Hand
Posts: 53
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two spots under were I have two put try catch statements with exception errors in I am not sure were or how to put them to accomplish whats listed below and help would be greatly appreciated. I had it working i started inserting another try catch statement under the add butoon it not working either.
The exception error part is what i am missing from below I have tried with try catch statments
requirments
Part number (a TextField). For entering the part number. This value will be used as the key for storing and retrieving a specific Part object from the Map collection. The only edit that must be directly performed by the application is to verify that the part number does not exceed that of the HTML "maxPart" parameter (see below). Other editing (testing for a value less than zero) should be performed by methods of the Part class which may throw an Exception object.
Description (a TextField). For entering and displaying the part description. It must never be null or blank when attempting to add a Part object to the Map collection. The editing should be performed by methods of the Part class which may throw an Exception object.
Quantity (a TextField). For entering and displaying the part quantity. It must never be null, blank, or less than zero when attempting to add a Part object to the Map collection. The editing should be performed by methods of the Part class which may throw an Exception object.
Add (a Button). When clicked, test the part number to determine if it is less than the maximum part number specified by the HTML "maxPart" parameter value (see processing notes below). If so, attempt to construct a Part object from the values in the text fields. If a construction error occurs, display an error message in the message area. If construction succeeds and if the part number is NOT already in the key set, add the Part object to the Map. Display the result in the message area ("Add successful", "Duplicate object", etc.).

 
Salman Khattak
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I found one place you def need try/catch
Try the following where you use the "parseInt()"

I will look for the second place. BTW in your code you are using the dreaded empty catch pitfall. Never do this

If you don't handle the exception at least spit out the error for debugging purposes. Otherwise your code will be crashing with a clue!
[ November 05, 2003: Message edited by: Salman Khattak ]
 
Salman Khattak
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by jon ladd:




Yes, you need a try/catch block here. Why? Because class Part constructor throws an exception and you need to catch it whenever you create an object Part. Hope that was helpful
 
chris czinder
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well one are that you should be checking for exceptions is in your part class when you set the values...

that is one place where errors may occur as you are attempting to set the partNumber, description, and quantity. if for any reason the information passed is wrong, ie null, or negative. It could blow up the program
 
jon ladd
Ranch Hand
Posts: 53
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried it few differnt ways and nothing compiles this way,
 
chris czinder
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What kind of compile errors are you getting?
Are they something like this?

[ November 05, 2003: Message edited by: chris czinder ]
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Make sure that your open/close braces match ...
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic