4

I've got a rather simple IntelliJ/tool question here:
I'm currently dealing with some legacy code and started to rework stuff here and there. What I stumbled upon very often are declared (checked) exceptions in the method signature, although these exceptions are never thrown within the body.
These declarations are also not enforced by an interface or something alike, because this problem occurs mainly in MVC controllers, that apparently were always copied and pasted over and over again.
I would like to know if there's a way to search for such declared exceptions with IntelliJ.
Because if I put my caret at the throws keyword it does not highlight anything, because the declared exception is never thrown, but the editor does not show me an error marking either, what I would really appreciate : )
Is there an option in IntelliJ to enable this feature or does a plugin exist that would do that job?

Thanks in advance.

Unknown Id
  • 460
  • 3
  • 12

2 Answers2

8

Open settings, select Editor -Inspections. Find the Java - Declaration reduncancy - Redundant throws clause and tick it.

Then run code analysis, though Analyze - Inspect code on the top level menu.

enter image description here

Tobb
  • 11,850
  • 6
  • 52
  • 77
  • Indeed, the problem was that this kind of analysis is only available on the fly if your methods are final/static. Without triggering `inspect code` I could not see it. Thanks : ) – Unknown Id Jan 29 '16 at 12:36
6
Menu > Analyze > Run Inspection by Name > Redundant throws clause

enjoy:)

ZhongYu
  • 19,446
  • 5
  • 33
  • 61