While working on a project I came across this code intended for a production system:
public static void sleepUntil(long millisecondToWake) {
while (true) {
long currentMillisecond = System.currentTimeMillis();
if (currentMillisecond >= millisecondToWake) {
break;
}
try {
Thread.sleep(millisecondToWake - currentMillisecond);
}
catch (InterruptedException ignoredException) {
// do nothing
}
}
}
I've always stuck to the basic principle of never dropping exceptions as exposed by Joshua Bloch in Effective Java as well as supported with my own extensive experience having to debug code where someone else did drop an exception. To date, I have not found a case where it is a good idea (sometimes catching checked exception and throwing an runtime is debatably reasonable but I am not talking about those cases here).
Thanks in advance for any comments.