Java Reference
In-Depth Information
if statement throws
exception if entered value
is less than or equal to zero
FIGURE 4-20
The try and catch statements are ready to be tested. The code can be tested
by entering alphabetic data, a negative sales amount, and a zero sales amount in
the Input dialog box. The program will catch the exception and display an Error
message box with the message coded in line 42. The following steps compile and
test the try and catch statements.
To Compile and Test the try and catch Statements
1. With the Data Disk in drive A, compile the program by clicking Compile
Java on the Tools menu. If TextPad notifies you of errors, click
Commission.java in the Selector window, fix the errors, and then
compile again. When the program compiles with no errors, click Run
Java Application on the Tools menu.
2. When the Input dialog box displays, type seventy-nine in the text
box. Click the OK button.
3. When the Error dialog box displays, click the OK button. Click the Close
button in the command prompt window title bar.
4. Run the program again. When the Input dialog box displays, type -382
in the text box. When the Error dialog box displays, click the OK button.
Click the Close button in the command prompt window title bar.
(continued)
Search WWH ::




Custom Search