当使用Guava中的Throwables.propagate(e)时,如何处理InterruptedException最佳实践是什么?
我喜欢在没有抛出已检查异常且异常处理由调用者负责的方法中使用Throwables.propagate(e),但它不能像我期望的那样处理InterruptedException。
我不想失去线程被中断的信息,因此我最终会写出类似以下的代码:
public void run() {
Callable c = ...;
try {
c.call();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw Throwables.propagate(e);
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
在Guava中有没有这样做的方法?是否有一种(向后兼容的?!)方法可以使用类似Throwables.propagate()的东西,如果它正在包装和传播InterruptedException,它会将线程设置为中断状态?