Networking code sometimes throws UnknownHostException

前端 未结 4 864
迷失自我
迷失自我 2020-11-29 13:30

I am trying to data from a server. Sometimes my code fails due to an UnknownHostException. Why is that? What is the cause of this problem?

4条回答
  •  爱一瞬间的悲伤
    2020-11-29 13:53

    If the DNS resolution fails intermittently, catch the exception and try again until you get name resolution. You can only control, what you can control... And if you can't control/fix the DNS server, make your app robust enough to handle the quirky DNS server.

提交回复
热议问题