Java Reference
In-Depth Information
} finally {
closeIgnoringException(in);
closeIgnoringException(out);
}
private static void closeIgnoringException(Closeable c) {
if (c != null) {
try {
c.close();
} catch (IOException ex) {
// There is nothing we can do if close fails
}
}
}
In summary, when you call the close method in a finally block, protect it with a nested TRy -
catch to prevent propagation of the IOException . More generally, handle any checked exception
that can be thrown within a finally block rather than letting it propagate. This is a special
case of the lesson in Puzzle 36 , and the same lessons for language designers apply.
< Day Day Up >
 
 
Search WWH ::




Custom Search