<legend id='1H49X'><style id='1H49X'><dir id='1H49X'><q id='1H49X'></q></dir></style></legend>

      <small id='1H49X'></small><noframes id='1H49X'>

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

        • <bdo id='1H49X'></bdo><ul id='1H49X'></ul>
      1. 如何解决“定义并抛出专用异常而不是使用通用异常".

        时间:2024-05-10
          <bdo id='S4DDJ'></bdo><ul id='S4DDJ'></ul>
        • <tfoot id='S4DDJ'></tfoot>
            • <legend id='S4DDJ'><style id='S4DDJ'><dir id='S4DDJ'><q id='S4DDJ'></q></dir></style></legend>

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

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

                2. 本文介绍了如何解决“定义并抛出专用异常而不是使用通用异常".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  当两个列表的长度不相等时,我需要 throw RuntimeException.我们正在使用 SonarQube 工具进行代码审查.

                  I need to throw RuntimeException when length of two lists is not equal. We are using SonarQube tool for code review purpose.

                  代码如下:

                  if (objctArray.length != columnArray.length) {
                                  throw new RuntimeException(String.format("objctArray and columnArray length is not same. objctArray length = %d, columnArray length = %d", objctArray.length, columnArray.length));
                              }
                  

                  现在,SonarQubethrow new RuntimeException 行提出了 Define 并抛出专用异常而不是使用通用异常. 的问题.我不知道我可以替换哪个异常来解决 SonarQube 问题.

                  Now, SonarQube raises issue that Define and throw a dedicated exception instead of using a generic one. at throw new RuntimeException line. I don't know which exception I can replace to resolve SonarQube issue.

                  推荐答案

                  如果这两个列表是传递给方法的参数,IllegalArgumentException 将是一个很好的抛出候选者.它是 RuntimeException 的子类,所以你仍然会抛出一种 RuntimeException.

                  If those two lists are arguments passed to a method, IllegalArgumentException would be a good candidate to throw. It's a sub-class of RuntimeException, so you'll still be throwing a kind of RuntimeException.

                  if (objctArray.length != columnArray.length) {
                      throw new IllegalArgumentException(String.format("objctArray and columnArray length is not same. objctArray length = %d, columnArray length = %d", objctArray.length, columnArray.length));
                  }
                  

                  这篇关于如何解决“定义并抛出专用异常而不是使用通用异常".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 Tomcat 上使用 JaCoCo Java 代理获取我的应用程序的代码覆盖率 下一篇:声纳插件 Eclipse

                  相关文章

                  <small id='7DAhU'></small><noframes id='7DAhU'>

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

                  <legend id='7DAhU'><style id='7DAhU'><dir id='7DAhU'><q id='7DAhU'></q></dir></style></legend>
                    <bdo id='7DAhU'></bdo><ul id='7DAhU'></ul>