简体   繁体   English

在Intellij Idea中添加throws声明的快捷方式

[英]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. 我正在使用eclipse很长一段时间,但是在去年左右,我正在尝试习惯Intellij Idea,因为这是他们在我目前的工作场所使用的东西。

One feature I can not find a substitute in Idea is ability of eclipse to add throws declarations. 我无法在Idea中找到替代品的一个功能是eclipse添加抛出声明的能力。 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. 在Eclipse中,我可以右键单击带下划线的字符串,然后选择“添加抛出声明”,然后将其添加到我的方法签名中,但我无法在Idea中找到它。 Is there such a functionality in Idea? Idea中有这样的功能吗?

When a piece of code needs error handling, IntelliJ underlines it with red. 当一段代码需要处理错误时,IntelliJ会用红色表示它。 Set your pointer on that piece of code and press ALT + ENTER . 将指针设置在该段代码上,然后按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. IntelliJ现在应该可以选择用try / catch包围它,添加一个catch子句,或者添加一个throws声明。

In your case: click the underlined code → ALT + ENTERAdd Exception to Method Signature 在您的情况下:单击带下划线的代码→ ALT + ENTERAdd Exception to Method Signature

IntelliJ also has a shortcut to place your cursor on the next error or warning: F2 . IntelliJ还有一个快捷方式,可将光标置于下一个错误或警告上: F2 This – especially in combination with ALT + ENTER – is quite useful. 这 - 特别是与ALT + ENTER结合使用 - 非常有用。

在Mac上它也是Alt + Enter,但你必须在红线的末尾,表明你必须处理异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM