Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

shortcut to add throws declaration in Intellij Idea

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?

like image 672
J.J Avatar asked Mar 14 '13 14:03

J.J


People also ask

What is Ctrl h in IntelliJ?

Ctrl + H = "Type Hierarchy" view = shows a tree of parent and child classes of this class. Ctrl + Shift + A = "It does a search as you type through all the commands in intellij. Not only that but when you find the command you want it also displays the corresponding shortcut key next to it!"

What is Ctrl Shift O in IntelliJ?

In Eclipse, you press CTRL + SHIFT + O “Organize Imports” to import packages automatically. For IntelliJ IDEA, if you press CTRL + ALT + O “Optimize Imports”, it just removes some unused imports, never imports any package.

What is Ctrl Alt L in IntelliJ?

Sometimes code formatting can get out of sync, but there's an easy fix in IntelliJ IDEA. You can use ⌘⌥L (macOS), or Ctrl+Alt+L (Windows/Linux) to reformat a selection of code according to your reformat settings.


1 Answers

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.

like image 133
bortdc Avatar answered Sep 22 '22 00:09

bortdc