Java Remove repeated try, catch, finally boilerplate from DAO
I have a DAO class with many methods that have a lot of repeated code along the lines of: - public void method1(...) { Connection conn = null; try { //custom code here } catch (SQLException e) { LOG.error("Error accessing the database.", e); throw new DatabaseException(); } catch (QueryNotFoundException e) { LOG.error("Error accessing the database.", e); throw new DatabaseException(); } finally { if (conn != null) connectionPool.returnConnection(conn); } public void method2(...) { Connection conn = null; try { //different custom code here } catch (SQLException e) { LOG.error("Error accessing