try/catch expression

Tom Ball tball at google.com
Wed Nov 11 12:35:12 PST 2009


I think you can do your preferred try/catch example using JavaFX Script.
That's outside of the discussion of Coin changes, but suggests that rather
than this list working toward making Java be the superset of all JVM
languages, we should instead encourage the use of other JVM languages when
appropriate.

Tom

On Wed, Nov 11, 2009 at 10:10 AM, Lawrence Kesteloot <lk at teamten.com> wrote:

> 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