捕获由临时网络错误引起的异常

问题描述:

我必须下载一些URL,可能会发生这样的情况:在操作过程中可能会出现一些异常,例如 java.net.NoRouteToHostException 。我认为这是一个暂时的错误异常,因为下载可以成功,如果你在一段时间后重试。

所以,我想捕获所有与临时错误相关的异常,我已经开始这些: java.net.NoRouteToHostException java.net.SocketException

可以列出其他例如这些?

I have to download some URLs, and it can happen that during the operations some exception may occur, like java.net.NoRouteToHostException. I consider it a temporary error exception, as the download can succeed if you retry it after some time.
So, I'd like to catch all those exceptions related to temporary errors, and I've started with these: java.net.NoRouteToHostException, java.net.SocketException
Can you list other exceptions like these?

java.net.SocketException 是父的 java.net.NoRouteToHostException ,所以你可能只能抓住父母。 SocketException 的其他孩子是 BindException ConnectException code> PortUnreachableException 。也许只要在你的情况下只捕捉 SocketException ...

java.net.SocketException is the parent of java.net.NoRouteToHostException so you could maybe catch only the parent. The others childs of SocketException are BindException, ConnectException and PortUnreachableException. Maybe it's ok to catch only SocketExceptionin your case...