In this particular example, this does not seem reasonable. In particular, if the user wants to exit the program (for example), the JVM will freeze until your sleeping method ends, which seems unreasonable.
IMO, the only situation in which you can safely ignore InterruptedException is where:
- you have full control over the thread executing your method, and
- you exit immediately after ignoring the exception.
In any other situation, you must: reset the aborted flag and exit quickly.
For example, this will be fine:
//the task is local, nobody else can access it final Runnable localRunnable = new Runnable() { public void run() { //catch, ignore and exit immediately try { Thread.sleep(10000); } catch (InterruptedException e) {} } } //it is your own thread and you have full control over it new Thread(localRunnable).start();
source share