Search code examples
javaintellij-ideaidejetbrains-ideautomated-refactoring

IntelliJ Idea: automatically remove unnecessary "throws" declarations


Often after refactoring throws sections become unnecessary. IntelliJ highlights them with grey showing that they can be removed, but I'd like to remove them automatically (just like unused imports get removed via ctrl+alt+O).

Q: Is there a way to automatically remove unused throws sections within a class? Is there a shortcut for that?


Solution

  • There are two ways I am aware of:

    1. Quick Code Cleanup.

    I use the ^C combination. There was no default hotkey.

    enter image description here

    You can specify code cleanup scope. It might be the whole project or a custom scope.

    enter image description here

    1. Removing the redundant clause.

    It gets accessible on the focused clause (you put the mouse on the element) with alt.

    enter image description here