I am getting an error and don't know why:
Error:(43, 50) java: unreported exception java.lang.Exception; must be caught or declared to be thrown
public static String readString() throws Exception {
//write your code here
InputStream inputStream = System.in;
Reader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
return bufferedReader.readLine();
}
......this seems to have solved the error...but why?? I compared before and after the "fix" and the code is the same...already had Exception ??
The asker of this question here: https://stackoverflow.com/questions/15412555/shortcut-to-add-throws-declaration-in-intellij-idea
Said he was accustomed to Eclipse and had just switched to InteliJ
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+ENTER → Add Exception to Method Signature
Kent Hervey
Level 16
Exception error
Under discussion
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
Roman
30 October 2019, 13:29
I do not get an error in a similar situation ...
0