11.5 Recovering from an Exception

In the next example, we read data from a file and use that data to draw a flag. Figure 11.8 shows the contents of the HungarianFlag.txt file. We also show how to catch and recover from an exception; that is, how to enable our program to continue to run when an exception occurs. The data is organized in a similar manner, but it is simpler than what is used by the GIF run-length encoding algorithm:

Figure 11.8The HungarianFlag.-txt File

300
15000 1.0 0.0 0.0
15000 1.0 1.0 1.0
15000 0.0 1.0 0.0
  • The first line is an integer storing the width of the flag.

  • Each line thereafter contains four numbers. The first number, an integer, stores the number of consecutive pixels (as we go left to right on the flag image) ...

Get Java Illuminated, 5th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.