try {
while (!current.interrupted() && numSeconds > 0) {
Thread.sleep(1000);
System.out.println(numSeconds--);
a++;
}
}
catch (InterruptedException e) {
if (a == 3) {
System.out.println("Go!");
} else if(a == 4){
System.out.println("Interrupted!");
}
}
Why the if loop, in the Catch, not working, and if i put the if loop en the try it work?
I solved it, but i have a
Resolved
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
B Sangappa
30 April 2020, 10:27solution
Hi, if you look at your catch block, the if condition (if (a == 3)) will not work for numSeconds = 3, because, we are only running RacingClock object's run method for 3(or less) seconds and you're interrupting the same object after 3.5 seconds by the time the process has already completed. You can check (a == 3) in try and (a == 4) in Catch block.
+2