以下处理方式有什么区别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
我有以下代码示例:
private boolean openThroughCommPort(IProgressMonitor monitor, int portNum)
throws InterruptedException, PortInUseException, IOException,
UnsupportedCommOperationException, TooManyListenersException,
UnsupportedVehicleException, InnerCanceledException {
...
}
Run Code Online (Sandbox Code Playgroud)
我不确定它是好方法 - 在方法签名中抛出许多异常.
也许你可以告诉我这个案子的最佳实践?