public int countChars3(String fileName) {
int total = 0;
FileReader r = null;
try {
r = new FileReader(fileName);
} catch (FileNotFoundException e) {
System.out.println("File named " + fileName + " not found. " + e);
total = -1;
}
try {
while (r.ready()) {
try {
r.read();
} catch (IOException e) {
System.out.println("IOException" + "occurred while counting " + "chars. " + e);
total = -1;
}
total++;
}
} catch (IOException e) {
System.out.println("IOExceptionoccurred while counting chars. " + e);
total = -1;
}
try {
r.close();
} catch (IOException e) {
System.out.println("IOExceptionoccurred while counting chars. " + e);
total = -1;
}
return total;
}
上記のコードは、もつれた混乱のtry-catchブロックの例です。コードを読むと、それらは乱雑に見えます。ネストされたトライキャッチがいくつかあります。大まかに言えば、このもつれた混乱したコードブロックは何を実証しようとしていますか?