如何避免Sonar的“保留堆栈跟踪”违规?

时间:2014-02-12 05:28:11

标签: java

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());
}

1 个答案:

答案 0 :(得分:2)

您已记录每个例外;就保存信息而言,这应该足够了,如下所示,

LOGGER.info("Unexpected Exception has occurred", e);     

或者如果可以,你应该抛出PhDashException因为,就保存信息而言,你应该足够了

throw new PhDashException(pHDashExceptionMapper);