osdir.com

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [DBCP] org.apache.commons.dbcp2.datasources.InstanceKeyDataSourceFactory.closeAll() does not close all


Good question. 
I’ve never liked `close()` methods that throw exceptions. What is the client code supposed to do?

It certainly makes sense to me to first fulfill the promise of “closeAll”, which is to call `close` on all values (and not stop half-way through).

The remaining question is what to do with any exceptions (there could be multiple) that occurred during this process. 

One idea is to rethrow the first one. Another is to throw a MultipleExceptions from which the client code can obtain all exceptions that occurred. But then again, given that there is little that the client code can do with these exceptions, why not _return_ a list of the exceptions that occurred?

Remko

(Shameless plug) Every java main() method deserves http://picocli.info

> On Jun 11, 2018, at 1:14, Gary Gregory <garydgregory@xxxxxxxxx> wrote:
> 
> org.apache.commons.dbcp2.datasources.InstanceKeyDataSourceFactory.closeAll()
> does not close all if one of delegated close() calls throws an exception.
> 
> I would think we would want to close all no matter what and then save the
> first exception caught and rethrow it after all closes have been attempted.
> 
> Thoughts?
> 
> Gary

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xxxxxxxxxxxxxxxxxx
For additional commands, e-mail: dev-help@xxxxxxxxxxxxxxxxxx