Functional programming
Chris Angelico
rosuav at gmail.com
Tue Mar 4 15:01:54 EST 2014
On Wed, Mar 5, 2014 at 6:49 AM, Marko Rauhamaa <marko at pacujo.net> wrote:
> public ConnectionPool(int maxConnections, String url) throws SQLException {
> try {
> super(() -> {
> try {
> return DriverManager.getConnection(url);
> } catch ( SQLException ex ) {
> throw new WrappedSqlException(ex);
> }
> }, maxConnections);
> } catch (WrappedSqlException wse) {
> throw wse.getSqlException();
> }
> }
>
> ===JAVA END=============================================================
>
> ===PYTHON BEGIN=========================================================
>
> def __init__(self, max_connections, url):
> super().__init__(lambda: DriverManager.get_connection(url), max_connections)
You're not doing the same thing, though. The Java rigmarole is to
ensure that an SQLException thrown in getConnection will propagate up,
despite (presumably) something inside the equivalent of
super().__init__ that swallows SQLExceptions. Of course it looks
tidier when you don't do the messy bit.
ChrisA
More information about the Python-list
mailing list