commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Henri Yandell <bay...@generationjava.com>
Subject Re: [lang] New feature: Close method for Objects
Date Sun, 30 Jun 2002 21:44:12 GMT
My only worry with this one is logging.

When errors occur in lang, and Exceptions are being supressed, what form
of logging should occur? Or do we just make them quiet.

Lastly, what performance drop do you see from using the reflection here?
I'll assume you're caching the Method objects, so performance shouldn't be
that big an issue.

Hen

On Sun, 30 Jun 2002, Rand McNeely wrote:

> I've attached a close method for Objects.  It uses reflection to call
> close on the object passed to it and returns any exceptions (without
> throwing them).  I have found this to be very useful as most classes
> which have a close method declare to throw an exception that can't be
> dealt with in a meaningful way (java.io.InputStream,
> java.sql.Connection, etc).  This leads to constructs like this:
>
> finally {
> 	try {
> 		if (statement != null) {
> 			statement.close();
> 		}
> 	} catch (SQLException ignored) {
> 	}
> 	try {
> 		if (connection != null) {
> 			connection.close();
> 		}
> 	} catch (SQLException ignored) { }
> 	}
> }
>
> which would be much cleaner like this:
>
> finally {
> 	Objects.close(statement);
> 	Objects.close(connection);
> }
>
> Rand McNeely
>


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message