【问题标题】:parameter to suppresswarnings for catching `Exception` in IntelliJ Idea用于在 IntelliJ Idea 中捕获“异常”的抑制警告的参数
【发布时间】:2017-05-25 04:57:32
【问题描述】:

我正在使用 PMD 和 checkstyle 并使用如下代码

public void testMethod() {
try {
            // do something
            } catch (Exception e) {
                logger.error("Error updating benchmark {} state", benchmarkId, e);
            }
}

但它在质量检查过程中失败,因为testmethod 正在捕获Exception。我想使用 @SuppressWarnings("PMD.SignatureDeclareThrowsException") 但它不起作用并尝试搜索应该是正确的注释来处理它但找不到它。

让我知道什么应该是正确的 PMD 注释来抑制在 Intellij Idea 中捕获 exception 的警告。

【问题讨论】:

  • 将光标悬停在警告上,使用 ALT + ENTER 键,然后使用右箭头键打开子菜单。该子菜单具有“Suppress for line”或“Suppress for method”等选项。

标签: java intellij-idea pmd suppress-warnings


【解决方案1】:

SignatureDeclareThrowsException 是禁止进行方法声明的规则,例如void myMethod() throws Exception

在这里,您可能在此块上被报告了AvoidCatchingGenericException(检查this)。因此,您应该改用@SuppressWarnings("PMD.AvoidCatchingGenericException")

【讨论】:

  • 请注意,对于 chckstyle,这是@SuppressWarnings({"checkstyle:IllegalCatch"})
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-09
  • 2011-09-06
  • 1970-01-01
  • 1970-01-01
  • 2021-02-19
相关资源
最近更新 更多