Consider the following code:
BufferedWriter wr;
try {
wr = Files.newBufferedWriter(path, Charset.forName("US-ASCII"));
wr.write("\u00ff"); // unmappable character written
wr.flush(); // expectedly throws IOE
} catch (IOException ioe) {
. . .
} finally {
if (wr != null) {
wr.close(); // unexpectedly throws IOE !!!
}
}
The IOE (actually UnmappableCharacterException) is thrown by close() method unexpectedly.
BufferedWriter wr;
try {
wr = Files.newBufferedWriter(path, Charset.forName("US-ASCII"));
wr.write("\u00ff"); // unmappable character written
wr.flush(); // expectedly throws IOE
} catch (IOException ioe) {
. . .
} finally {
if (wr != null) {
wr.close(); // unexpectedly throws IOE !!!
}
}
The IOE (actually UnmappableCharacterException) is thrown by close() method unexpectedly.