Kun*_*nak 18 java exception try-catch interrupted-exception throws
在我的方法之一中,中断异常和执行异常即将到来。我像这样输入了 try catch 。
try{
//my code
}catch(InterruptedException|ExecutionException e)
Log.error(" logging it");
throw new MonitoringException("it failed" , e)
//monitoringexception extends RunTimeException
Run Code Online (Sandbox Code Playgroud)
同样在我的方法中,我抛出了 InterruptedException,ExecutionException
我在声纳中遇到严重错误 - 重新中断此方法或重新抛出“ InterruptedException”
有人知道怎么修这个东西吗。
请立即帮助。
jum*_*key 25
将“重新中断”作为最佳实践:
try{
//some code
} catch (InterruptedException ie) {
logger.error("InterruptedException: ", ie);
Thread.currentThread().interrupt();
} catch (ExecutionException ee) {
logger.error("ExecutionException: ",ee);
}
Run Code Online (Sandbox Code Playgroud)
通常,当线程被中断时,中断线程的人都希望线程退出当前正在执行的操作。
但是,请确保您不要多次捕获:
catch (InterruptedException | ExecutionException e) {
logger.error("An error has occurred: ", e);
Thread.currentThread().interrupt();
}
Run Code Online (Sandbox Code Playgroud)
我们不希望 ExecutionException 被“重新中断”。
奖励:
如果你有兴趣,你可以在这里玩例子
干杯
| 归档时间: |
|
| 查看次数: |
15631 次 |
| 最近记录: |