Exceptions, and how best to retry when a connection is reset?

前端 未结 3 2027
不知归路
不知归路 2021-02-08 23:43

I have some code which connects to a URL to download a file, and then performs some processing on it. However, sometimes I am receiving the error java.net.SocketException:

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-09 00:33

    I've been wired to think that swallowing an exception is always bad, but I think here, that's the only way to tell if the connection was indeed reset. I guess you are handling the exception according to your requirements, so that's all the matters.

    But I would, however, make it so you don't swallow the last exception. If it fails three times, you'll want to rethrow that exception or fail gracefully somehow.

提交回复
热议问题