编程语言
首页 > 编程语言> > java-Findbugs contrib:方法从没有历史记录的catch块中抛出替代异常

java-Findbugs contrib:方法从没有历史记录的catch块中抛出替代异常

作者:互联网

fb-contrib抱怨

Method throws alternative exception from catch block without history

在我的try / catch块之一中.

如何解决?是否有解决此问题的详细说明?

解决方法:

捕获了原始异常,您的代码引发了另一个异常,而没有在java.lang.Throwable原因中包含原始异常

发现了一些here

This method catches an exception, and throws a different exception, without incorporating the
original exception. Doing so hides the original source of the exception making debugging and fixing
these problems difficult. It is better to use the constructor of this new exception that takes an
original exception so that this detail can be passed along to the user.

FindBugs贡献很大!
因此,将原因传递给我们,将其记录下来,…对所捕获的内容进行处理.
希望这对某人有帮助.

例:

try {
  ...
} catch (final SomeException theOriginalCause) {
  // throw new SomeOtherException(); // Bad !
  throw new SomeOtherException(theOriginalCause); // Good.
}

标签:findbugs,java
来源: https://codeday.me/bug/20191119/2033905.html