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());
}
最佳答案
您已记录每个异常;就保存信息而言,如下所述就足够了,
LOGGER.info("Unexpected Exception has occurred", e);
或者,如果可以的话,您应该重新抛出
PhDashException
,因为就保存信息而言,您应该足够了throw new PhDashException(pHDashExceptionMapper);
关于java - 如何避免Sonar的“保留堆栈跟踪”冲突?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21719427/