如何确定对未经检查的异常使用什么异常?例如
@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) {
LOG.info("Inisde FarmersLegalAuditJsonDataServlet do post method");
try {
String auditKey = request.getParameter("auditKey") != null ? request.getParameter("auditKey") : StringUtils.EMPTY;
LOG.info("auditKey:{}",auditKey);
if (StringUtils.isNotEmpty(auditKey)) {
//Calling service to serach in the repository
String redirectPath = farmersLegalAuditSearchService.getJsonFilePath(auditKey, request);
LOG.info("redirectPath:{}",redirectPath);
if(StringUtils.isNotEmpty(redirectPath) && !StringUtils.equalsIgnoreCase(redirectPath, "EMPTY_RESULT")) {
response.sendRedirect(redirectPath);
} else if(StringUtils.isNotEmpty(redirectPath) && StringUtils.equalsIgnoreCase(redirectPath, "EMPTY_RESULT")) {
response.getWriter().print("No results found");
} else {
response.getWriter().print("There is some backend issue. Please try later.");
}
} else {
LOG.info("auditKey is empty/null");
response.getWriter().print("There is some backend issue. Please try later.");
}
} catch (IOException ioe) {
LOG.error("IOException:", ioe);
} catch(Exception ex) {
LOG.error("Exception:",ex);
}
}
对于catch(Exception ex) {LOG.error("Exception:",ex); }
SonarQube 不想要通用异常,请注意当我删除 catch(Exception E) 时,项目构建得很好,它甚至需要异常,如果需要,我应该使用哪一个?