关于记录和在Sonar中重新抛出异常的投诉

huangapple 未分类评论49阅读模式
英文:

complaining about logging and rethrowing the exception in sonar

问题

我在程序中有以下一段代码,并且在将其与Maven集成后,我正在运行SonarQube进行代码质量检查。

然而,Sonar提示我应该记录(log)这个异常或重新抛出(rethrow)它。

我在这里漏掉了什么?难道我没有已经记录这个异常吗?

public AccountResponse getAccountStatus(AccessIDSearchResponse accessIDResponse) {
    accountResponse = null;
    try {
        AccountRequest request = new AccountRequest();
    } catch (ServiceException serviceException) {
        log.error("getAccountStatus-GotServiceException =" + ExceptionUtils.getStackTrace(serviceException));
        throw serviceException;
    } catch (Exception e) {
        throw new ServiceException(ErrorMessages.EPO_SYSTEM_ERROR, e.getMessage());
    }
    return accountResponse;
}

[![enter image description here][1]][1]


<details>
<summary>英文:</summary>

I have the following piece of code in my program and I am running SonarQube for code quality check on it after integrating it with Maven.

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?

    public AccountResponse  getAccountStatus(AccessIDSearchResponse accessIDResponse) {
    	accountResponse = null;
    	try {
    		AccountRequest request = new AccountRequest();
    	} catch (ServiceException serviceException) {
    		log.error(&quot;getAccountStatus-GotServiceException =&quot; + ExceptionUtils.getStackTrace(serviceException));
    		throw serviceException;
    	} catch (Exception e) {
    		throw new ServiceException(ErrorMessages.EPO_SYSTEM_ERROR, e.getMessage());
    	}
    	return accountResponse;
    }


[![enter image description here][1]][1]


  [1]: https://i.stack.imgur.com/t0sgW.png

</details>


huangapple
  • 本文由 发表于 2020年5月29日 19:41:51
  • 转载请务必保留本文链接:https://java.coder-hub.com/62085170.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定