In my main method is this code:
int hours = getHours();
Here is the get hours() code:
public static int getHours() {
int hours = 0;
boolean hoursNotOk = true;
do {
try {
hours = console.nextInt();
hoursNotOk = false;
}catch(Exception e) {
System.out.print(e);
}finally {
if(hoursNotOk) {
System.out.print(", please re-enter the hours again:");
}else {
System.out.print("**hours input accepted**");
}
}
}while(hoursNotOk);
return hours;
}
For the first time console.nextInt() ask me for input, so lets say I put in a "two" in the console, it will throw an exception and loop through the try block again but this time it did not ask me for input and keeps printing out from the catch and finally block, why is this happening?