相关疑难解决方法(0)

在Java中处理InterruptedException

以下处理方式有什么区别InterruptedException?最好的方法是什么?

try{
 //...
} catch(InterruptedException e) { 
   Thread.currentThread().interrupt(); 
}
Run Code Online (Sandbox Code Playgroud)

要么

try{
 //...
} catch(InterruptedException e) {
   throw new RuntimeException(e);
}
Run Code Online (Sandbox Code Playgroud)

编辑:我也想知道这两个使用的场景.

java multithreading exception-handling interrupted-exception

283
推荐指数
6
解决办法
15万
查看次数

通常,如果方法抛出大量异常?

我有以下代码示例:

 private boolean openThroughCommPort(IProgressMonitor monitor, int portNum)
       throws InterruptedException, PortInUseException, IOException,
       UnsupportedCommOperationException, TooManyListenersException,
       UnsupportedVehicleException, InnerCanceledException {
        ...
       }
Run Code Online (Sandbox Code Playgroud)

我不确定它是好方法 - 在方法签名中抛出许多异常.

也许你可以告诉我这个案子的最佳实践?

java exception

0
推荐指数
1
解决办法
117
查看次数