Sonar为以下代码提供了严重违规错误(“保留堆栈跟踪”)。以下方法用于抛出异常。我应该采取什么措施来克服这种违规行为?
public void exceptionHandler(String exception) throws PhDashException {
String exceptionMsg = exception.replaceAll("-", "_");
ExceptionPhDash pHDashExceptionMapper = new ExceptionPhDash();
try {
pHDashExceptionMapper = new ObjectMapper().readValue(exceptionMsg, ExceptionPhDash.class);
} catch (JsonParseException e) {
LOGGER.info(e.getMessage());
} catch (JsonMappingException e) {
LOGGER.info(e.getMessage());
} catch (IOException e) {
LOGGER.info(e.getMessage());
}
throw new PhDashException(pHDashExceptionMapper.getMessage());
}
答案 0 :(得分:2)
您已记录每个例外;就保存信息而言,这应该足够了,如下所示,
LOGGER.info("Unexpected Exception has occurred", e);
或者如果可以,你应该抛出PhDashException
因为,就保存信息而言,你应该足够了
throw new PhDashException(pHDashExceptionMapper);