【发布时间】:2019-10-24 13:07:47
【问题描述】:
对于下面的代码,Sonarqube 显示错误,说“要么记录或重新抛出此异常”。 fof catch 块,我们怎么处理呢
private ResponseEntity<String> getResponse(String url,
String logName,
HttpMethod httpMethod,
HttpEntity<String> httpEntity,
HttpServletRequest httpServletRequest)
{
httpServletRequest.setAttribute("api", logName);
ResponseEntity<String> checkEntity;
try {
if(logName.equals("Activate All Offer Api")){
checkEntity = requestFactory.getRestTemplate().exchange(url, httpMethod, httpEntity, String.class);
}else {
checkEntity = restTemplate.exchange(url, httpMethod, httpEntity, String.class);
}
} catch (Exception e) {
throw new LocalHttpClientErrorException(e.getLocalizedMessage());
}
return checkEntity;
}
【问题讨论】:
-
它告诉你正确地重新抛出异常,正确地并不意味着切断原始异常的堆栈跟踪,只使用本地化的异常消息。