gpt4 book ai didi

java - 如何避免 Sonar 的 "preserve stack trace"违规?

转载 作者:行者123 更新时间:2023-11-30 04:02:09 32 4
gpt4 key购买 nike

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 的 "preserve stack trace"违规?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21719427/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com