Java Reference
In-Depth Information
45
46 for ( int i = 0 ; i < numberOfValues; i++)
47 readValue(in, i);
48
49 if (in.hasNext())
50 throw new BadDataException( ÐEnd of
file expectedÑ );
51 }
52
53 /**
54 Reads one data value.
55 @param in the scanner that scans the data
56 @param i the position of the value to read
57 */
58 private void readValue(Scanner in, int i)
throws BadDataException
59 {
60 if (!in.hasNextDouble())
61 throw new BadDataException( ÐData value
expectedÑ );
62 data[i] = in.nextDouble();
63 }
64
65 private double [] data;
66 }
ch11/data/BadDataException.java
1 /**
2 This class reports bad input data.
3 */
4 public class BadDataException extends Exception
5 {
6 public BadDataException()
7 public BadDataException(String message)
8 {
9 super (message);
10 }
11 }
Search WWH ::




Custom Search