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

Adding Exception error problems

jon ladd
Ranch Hand

Joined: Feb 11, 2003
Posts: 53
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

Joined: Mar 23, 2003
Posts: 33
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 ]

SCJP Java 1.4 - 06/2003<br />Power corrupts and absolute power corrupts absolutely!
Salman Khattak
Ranch Hand

Joined: Mar 23, 2003
Posts: 33
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

Joined: Oct 02, 2002
Posts: 28
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

Joined: Feb 11, 2003
Posts: 53
I have tried it few differnt ways and nothing compiles this way,
chris czinder
Greenhorn

Joined: Oct 02, 2002
Posts: 28
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

Joined: Sep 03, 2003
Posts: 399

Make sure that your open/close braces match ...
 
 
subject: Adding Exception error problems