捕获由临时网络错误引起的异常 [英] Catching exceptions caused by temporary network errors

查看:166
本文介绍了捕获由临时网络错误引起的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须下载一些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...

这篇关于捕获由临时网络错误引起的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆