33

I am using eclipse for quite a while, but for last year or so I am trying to get used to Intellij Idea because that is what they use at my current workplace.

One feature I can not find a substitute in Idea is ability of eclipse to add throws declarations. In Eclipse I could right click on a underlined string and select "Add throws declaration" which then adds it to my method signature, but I can't find it for life of me in Idea. Is there such a functionality in Idea?

J.J
  • 633
  • 1
  • 6
  • 14

2 Answers2

72

When a piece of code needs error handling, IntelliJ underlines it with red. Set your pointer on that piece of code and press ALT+ENTER. IntelliJ should now give you the choice to either surround it with try/catch, add a catch clause, or to add a throws declaration.

In your case: click the underlined code → ALT+ENTERAdd Exception to Method Signature

IntelliJ also has a shortcut to place your cursor on the next error or warning: F2. This – especially in combination with ALT+ENTER – is quite useful.

Neuron
  • 5,141
  • 5
  • 38
  • 59
bortdc
  • 931
  • 9
  • 11
  • 2
    Is it possible that IntelliJ won't underline the code that needs error handling? If yes, then how to turn it on again? – Defozo Jul 15 '16 at 14:33
  • 3
    For anyone using a different set of key bindings, the action for this is called "Show Intention Actions". – Loiathal Mar 04 '19 at 19:28
2

On Mac it is Alt+Enter as well but you have to be at the end of the red line that shows that you have to handle the exception.

RajKon
  • 420
  • 1
  • 8
  • 20