本文介绍了声纳抱怨记录并重新抛出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!
问题描述
我的程序中有以下代码,在将其与 Maven 集成后,我正在运行 SonarQube 5 以对其进行代码质量检查.
I have the following piece of code in my program and I am running SonarQube 5 for code quality check on it after integrating it with Maven.
但是,Sonar 抱怨我应该记录或重新抛出此异常.
However, Sonar is complaining that I should Either log or rethrow this exception.
我在这里缺少什么?我还没有记录异常吗?
What am I missing here? Am I not already logging the exception?
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);
}
声纳不应该再打扰你了
这篇关于声纳抱怨记录并重新抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!