How can I improve this exception retry scenario?

前端 未结 10 1561
暗喜
暗喜 2020-12-13 19:39

I have a web service method I am calling which is 3rd party and outside of my domain. For some reason every now and again the web service fails with a gateway timeout. Its i

10条回答
  •  鱼传尺愫
    2020-12-13 20:10

    All of the answers so far assume that the reaction to any exception should be to retry the operation. This is a good assumption right up until it's a false assumption. You could easily be retrying an operation that is damaging your system, all because you didn't check the exception type.

    You should almost never use a bare "catch", nor "catch (Exception ex). Catch a more-specific exception - one you know you can safely recover from.

提交回复
热议问题