On Fri, 29 Oct 2004, Dain Sundstrom wrote:
I actually love closures, and think it would be a great addition to Java. I spend a lot of time tracking down poorly written try/finally blocks in people's code where they don't properly close DB connections, IO streams, Jar files, and even delete their temp files. A good closure library would virtually eliminate this type of programming errors.
1/
How about the Perl6 finally system where you can attach a try/catch to variables?
In Perl 6 it's:
my $p = P.new; POST { $p and $p.Done; } or my $p is post { .Done } = P.new;
So in Java it could be something like:
Connection conn = ds.getConnection(); finally(conn) { conn.close(); }; Connection conn = ds.getConnection() @ { conn.close(); }; Connection conn = ds.getConnection(); conn @ finally { conn.close(); };
Biggest problem is that I can't see a way to write that nicely.
2/ How about just being able to do multiple Exceptions in one block?
try { .... } catch(JMSException, RemoteException, SQLException e) { }
or possibly even:
try { .... } catch( (JMSException | RemoteException | SQLException) e) { }
The last one is interesting as it could be a larger concept allowing mixed-types; but from a finite set. Probably lots wrong with that idea :)
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]