<i id='eIufj'><tr id='eIufj'><dt id='eIufj'><q id='eIufj'><span id='eIufj'><b id='eIufj'><form id='eIufj'><ins id='eIufj'></ins><ul id='eIufj'></ul><sub id='eIufj'></sub></form><legend id='eIufj'></legend><bdo id='eIufj'><pre id='eIufj'><center id='eIufj'></center></pre></bdo></b><th id='eIufj'></th></span></q></dt></tr></i><div id='eIufj'><tfoot id='eIufj'></tfoot><dl id='eIufj'><fieldset id='eIufj'></fieldset></dl></div>
      • <bdo id='eIufj'></bdo><ul id='eIufj'></ul>

        <legend id='eIufj'><style id='eIufj'><dir id='eIufj'><q id='eIufj'></q></dir></style></legend>

        <small id='eIufj'></small><noframes id='eIufj'>

        <tfoot id='eIufj'></tfoot>
      1. SonarQube 抱怨:记录或重新抛出此异常

        SonarQube complains: Either log or rethrow this exception(SonarQube 抱怨:记录或重新抛出此异常)
        <i id='y5ujt'><tr id='y5ujt'><dt id='y5ujt'><q id='y5ujt'><span id='y5ujt'><b id='y5ujt'><form id='y5ujt'><ins id='y5ujt'></ins><ul id='y5ujt'></ul><sub id='y5ujt'></sub></form><legend id='y5ujt'></legend><bdo id='y5ujt'><pre id='y5ujt'><center id='y5ujt'></center></pre></bdo></b><th id='y5ujt'></th></span></q></dt></tr></i><div id='y5ujt'><tfoot id='y5ujt'></tfoot><dl id='y5ujt'><fieldset id='y5ujt'></fieldset></dl></div>
          <bdo id='y5ujt'></bdo><ul id='y5ujt'></ul>

              <tbody id='y5ujt'></tbody>
            • <small id='y5ujt'></small><noframes id='y5ujt'>

              <tfoot id='y5ujt'></tfoot>
              • <legend id='y5ujt'><style id='y5ujt'><dir id='y5ujt'><q id='y5ujt'></q></dir></style></legend>
                1. 本文介绍了SonarQube 抱怨:记录或重新抛出此异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在将代码与 Maven 集成后,我正在运行 SonarQube 5 进行代码质量检查.

                  I am running SonarQube 5 for code quality check after integrating the code with Maven.

                  Sonar 抱怨我应该:

                  Sonar is complaining that I should:

                  记录或重新抛出此异常.

                  Either log or rethrow this exception.

                  在以下代码中:

                  public static Date convertStringtoDate(String stringDate) {
                      stringDate = StringUtils.trimToNull(stringDate);
                      SimpleDateFormat dfm = new SimpleDateFormat("dd-MMM-yyyy");
                      Date date = null;
                  
                      if (stringDate != null) {
                          try {
                              date = dfm.parse(stringDate);
                          } catch (Exception e) {
                              logger.info("Cannot convert String to Date: ",convertStringtoDate(e.getMessage()));
                          }
                      }
                  
                      return date;    
                  }
                  

                  我在这里错过了什么?

                  推荐答案

                  首先,这种行为正确吗?您也尝试在异常消息上调用 convertStringtoDate 似乎有点奇怪.

                  First of all, is this behaviour correct? Seems a bit weird that you are trying to call convertStringtoDate on the exception message as well.

                  其次,我最近在使用 Sonar 时遇到了同样的问题.似乎您需要将整个异常作为参数传递给记录器,而不是 e.getMessage() 让 Sonar 意识到您正在记录异常.

                  Secondly, I had the same problem with Sonar recently. Seems like you need to pass the whole exception as a parameter to the logger, instead of e.getMessage() for Sonar to realize you are logging the exception.

                  试试这个:

                  public static Date convertStringtoDate(String stringDate){
                      stringDate = StringUtils.trimToNull(stringDate);
                      SimpleDateFormat dfm = new SimpleDateFormat("dd-MMM-yyyy");
                      Date date = null;
                      if(stringDate!=null){
                          try {
                              date = dfm.parse(stringDate);
                          } catch (Exception e) {
                              logger.info("Cannot convert String to Date: ", e);
                          }
                      }
                      return date;    
                  }
                  

                  这篇关于SonarQube 抱怨:记录或重新抛出此异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)

                      <tbody id='26OOL'></tbody>
                        • <bdo id='26OOL'></bdo><ul id='26OOL'></ul>

                            <tfoot id='26OOL'></tfoot>

                            <legend id='26OOL'><style id='26OOL'><dir id='26OOL'><q id='26OOL'></q></dir></style></legend>
                            <i id='26OOL'><tr id='26OOL'><dt id='26OOL'><q id='26OOL'><span id='26OOL'><b id='26OOL'><form id='26OOL'><ins id='26OOL'></ins><ul id='26OOL'></ul><sub id='26OOL'></sub></form><legend id='26OOL'></legend><bdo id='26OOL'><pre id='26OOL'><center id='26OOL'></center></pre></bdo></b><th id='26OOL'></th></span></q></dt></tr></i><div id='26OOL'><tfoot id='26OOL'></tfoot><dl id='26OOL'><fieldset id='26OOL'></fieldset></dl></div>
                          1. <small id='26OOL'></small><noframes id='26OOL'>