Is there a way to make eclipse report a general “catch (Exception e)” as an error/warning (in java)?

一世执手 提交于 2019-12-05 16:58:52

You can use Checkstyle eclipse plugin to do the same. Check 'IllegalCatch' section at documentation

FindBugs can report this:

REC: Exception is caught when Exception is not thrown (REC_CATCH_EXCEPTION)

This method uses a try-catch block that catches Exception objects, but Exception is not thrown within the try block, and RuntimeException is not explicitly caught. It is a common bug pattern to say try { ... } catch (Exception e) { something } as a shorthand for catching a number of types of exception each of whose catch blocks is identical, but this construct also accidentally catches RuntimeException as well, masking potential bugs.

Running the FindBugs, CheckStyle or PMD on every build would slow everyone's builds down, and I imagine that is why you are looking at the Eclipse approach. Unfortunately, that may also be problematic, depending on availability (and robustness) of plugins. Plus, you'll still take a performance hit in incremental and (especially) full project builds.

Another alternative would be to set up a Hudson continuous integration server and configure it to run style checkers, coverage tools and so on, tracking the results over time using the Sonar plugin.

As far as I can tell, it's not in the list at Window -> Preferences -> Java -> Compiler -> Errors/Warnings, and thus not possible - unless you fancy writing your own ecliple plugin.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!