Question about Exception handling
Hello again,
so I'm trying to write a complete OOP in Java(yay...well not quite). So, here is the problem. I am trying to pick up good habits and think of exceptional events as I code, so I wrote the following and I'm trying to catch a couple of events. The problem is that I'm getting an error asking for an identifier and I have a simple question. Are they listed somewhere or do I make them up? Please see code below:
Code:
try
{
Scanner userSelection = new Scanner(System.in);
int userselection = userSelection.nextInt();
}
catch (InputMismatchException)
{
System.out.print("You did not enter a integer.")
}
catch (NoSuchElementException)
{
System.out.println("There is nothing to read.");
}
catch (IllegalStateException)
{
System.out.println("This method has been invoked at the wrong time. Please try again when prompted.");
}
and I'm getting the following error:
Code:
----jGRASP exec: javac -g Numbers.java
Numbers.java:29: error: <identifier> expected
catch (InputMismatchException)
^
Numbers.java:33: error: <identifier> expected
catch (NoSuchElementException)
^
Numbers.java:37: error: <identifier> expected
catch (IllegalStateException)
^
3 errors
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
So my questions:
Do I make up a letter or name?...well actually, I doubt it, because I just tried and received a "Cannot find Symbol" error.
Do I look them up somewhere? If so where? I went to the nextInt API and it can throw three exceptions, so I tried to catch them but no luck. Any direction would be appreciated.
Thanks.