try/catch expression
Lawrence Kesteloot
lk at teamten.com
Wed Nov 11 10:10:18 PST 2009
One nice thing about having been on the coin-dev list is realizing
that I really like Java as it is. None of the proposals (including my
list comprehensions) have seem "worth it" (except ARM). But there's
one thing that repeatedly grosses me out, and bothers me more each
day:
Reader foo = new FileReader(filename);
This throws an IOException. I want to keep my catch clauses nice and
tight, so I end up writing:
Reader foo;
try {
foo = new FileReader(filename);
} catch (IOException e) {
log.warn("Cannot open file \"" + filename + "\" (" +
e.getMessage() + ")");
...;
}
The duplication of "foo" smells bad and four lines of noise were
added. I would prefer a try/catch expression:
Reader foo = try new FileReader(filename) catch (IOException e) {
log.warn("Cannot open file \"" + filename + "\" (" +
e.getMessage() + ")");
...;
}
I can't think of a change to Java that would please me more
day-to-day. Anyone else feel the same? Should I write this up for
JDK8?
Lawrence Kesteloot
More information about the coin-dev
mailing list