I am just not sure exactly what this section of code means.
try {
startGame(Integer.parseInt(clickedButton.getLabel()));
} catch (Exception ex) {
Logger.getLogger(JavaGame.class.getName()).log(Level.SEVERE, null, ex);
I am just not sure exactly what this section of code means.
try {
startGame(Integer.parseInt(clickedButton.getLabel()));
} catch (Exception ex) {
Logger.getLogger(JavaGame.class.getName()).log(Level.SEVERE, null, ex);
Integer.parseInt()
takes in a String
and returns an int
. So the label of that button must be String that holds a numeric value. The method startGame
must take in an int
to know which game to start. If the label is NOT a number, it will go into the catch
block by throwing a NumberFormatException
.
The catch
part is log4j
that will output to either a log file and/or console (depends on configuation) with the exception.
If Integer.parseInt() can not convert what ever string that is in clickedButton's Label then it will throw an error.
The error will then get catched by the try catch and create a log message with a level of severe with the stack trace that had happened.
It threw an exception because the clickedButton's Label is not a number.