Reverse-indenting exception handling blocks.

Lab Notes
Clarifying exception handling
by Matt Brenner
Listing 6. Reverse-indenting exception handling blocks.


1  private void
2  addlist (String listname, boolean uppercase)
3 {
4       BufferedReader    input = null;
5
6       String                text;
7
8
9           try {
10     input = new BufferedReader (new FileReader (new File (Setup. getinstalldir(), listname)));
11     while ((text = input.readLine()) != null) {
12          if (text.length() > 0) {
13             add (text, uppercase);
14         }
15     }
16         }
17         catch (IOException e) {
18             Errorlog.log (Syserrors.error BLOCKLIST1, e.toString()));
19         }
20         finally {
21     if (input != null) {
22              try {
23         input.close();
24              }
25              catch (IOException e) {}
26     }
27         }
28 }

Featured

Upcoming Events

AppTrends

Sign up for our newsletter.

I agree to this site's Privacy Policy.