gpt4 book ai didi

java - Sonar 提示记录并重新抛出异常

转载 作者:行者123 更新时间:2023-12-01 18:07:01 24 4
gpt4 key购买 nike

我的程序中有以下代码,在与 Maven 集成后,我正在运行 SonarQube 5 对其进行代码质量检查。

但是,Sonar 提示我应该记录或重新抛出此异常

我在这里缺少什么?我还没有记录异常吗?

 private boolean authenticate(User user) {
boolean validUser = false;
int validUserCount = 0;
try {
DataSource dataSource = (DataSource) getServletContext().getAttribute("dataSource");
validUserCount = new MasterDao(dataSource).getValidUserCount(user);
} catch (SQLException sqle) {
LOG.error("Exception while validating user credentials for user with username: " + user.getUsername() + " and pwd:" + user.getPwd());
LOG.error(sqle.getMessage());
}
if (validUserCount == 1) {
validUser = true;
}
return validUser;
}

最佳答案

你应该这样做:

try {
DataSource dataSource = (DataSource) getServletContext().getAttribute("dataSource");
validUserCount = new MasterDao(dataSource).getValidUserCount(user);
} catch (SQLException sqle) {
LOG.error("Exception while validating user credentials for user with username: " +
user.getUsername() + " and pwd:" + user.getPwd(), sqle);
}

Sonar 不再打扰您

关于java - Sonar 提示记录并重新抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60543807/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com