In my code i have try/catch block and there i'm catching mysql exception. However still its complaining that we need to handle this exception again within foreach loop.
As you can see here for normal for loop(after foreach logic) we dont need to handle it specifically. Can someone explain me the logic behind this?
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
IntStream.range(0, statuses.size())
.forEach(i -> statement.setString(i+1 , statuses.get(i)));
for (int i = 0; i < statuses.size(); ++i) {
statement.setString(i + 1, statuses.get(i));
}
return constructAPISummaryList(statement);
} catch (SQLException e) {
throw new APIMgtDAOException(e);
}
}
Error occurs at .forEach(i -> statement.setString(i+1, statuses.get(i)));
Error message: "Unhandled exception: java.sql.SQLException"