Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 635
Sasha Shpota Avatar asked Mar 19 '18 12:03

Sasha Shpota


2 Answers

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

like image 65
Andrew Tobilko Avatar answered Oct 02 '22 08:10

Andrew Tobilko


You can use Alt+Enter and select Cleanup code.

This will remove all unnecessary throws Exception declarations.

like image 28
Markus Spöri Avatar answered Oct 02 '22 07:10

Markus Spöri