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 块的例子。通过阅读代码,它们看起来确实很乱,有几个嵌套的 try-catch。概括地说,这个纠结的代码块试图展示什么?