shortcut to add throws declaration in Intellij Idea

J.J picture J.J · Mar 14, 2013 · Viewed 23.4k times · Source

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?

Answer

bortdc picture bortdc · Mar 14, 2013

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.