Common exception misuses in Java (and not only)
softwarecave.org
softwarecave.org
[1]:
Writer writer = null;
try {
writer = new FileWriter("/tmp/a");
writer.write("Line1");
writer.close();
} catch(FileNotFoundException e) {
// handle error
} catch (IOException ex) {
// handle error
}
[2]:
Writer writer = null;
try {
writer = new FileWriter("/tmp/a");
} catch(FileNotFoundException e) {
// handle error
} catch (IOException ex) {
// handle error
}
try {
writer.write("Line1");
} catch (IOException e) {
// handle error
}
try {
writer.close();
} catch (IOException e) {
// handle error
}