[英]How do I avoid Sonar's “preserve stack trace” violation?
Sonar gives a major violation error ("Preserve Stack Trace") for the following code. 声纳给出了以下代码的严重违反错误(“保留堆栈跟踪”)。 Following method is used to throw an exception.
以下方法用于引发异常。 What are the steps should I take to overcome this violation?
我应采取哪些步骤来克服这种违规行为?
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());
}
You've logged each exception; 您已记录每个异常; that should be enough as far as preserving information is concerned like below,
就保存信息而言,如下所述就足够了,
LOGGER.info("Unexpected Exception has occurred", e);
Or You should re throw the PhDashException
if you can, because, you should be enough as far as preserving information is concerned 或者,如果可以的话,应该重新抛出
PhDashException
,因为就保存信息而言,您就足够了
throw new PhDashException(pHDashExceptionMapper);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.