Can you please let me know if my code is correct? I'm studying for my test in two hours so I dont really have time to write an application to test it.
Question is: if I have a JLabel with a number as its label. simply a label that says 34 for example. I want to extract the number from the label. but i need to handle exceptions, i.e it's not a number, it can be a letter.
would my code below handle the exception correctly?
JLabel label = new JLabel("34");
int extracted;
this is what i would do
try{
extracted = Integer.parseInt(extracted.getText());
System.out.println("the number was: "+ extracted);
}
catch(IOException exception){
System.out.println(label.getText() + " is not a number");
}