Sasha Shpota
Sasha Shpota

Reputation: 10310

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?

Upvotes: 7

Views: 4873

Answers (2)

Markus Spöri
Markus Spöri

Reputation: 116

You can use Alt+Enter and select Cleanup code.

This will remove all unnecessary throws Exception declarations.

Upvotes: 2

Andrew
Andrew

Reputation: 49646

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

Upvotes: 5

Related Questions