[英]How to handle code for network failure and resume back?
suppose am in the middle of updating some information and the network connection goes off. 假设正在更新某些信息,并且网络连接断开。
How should i write my code to handle such situation and resume from where the code was last executing? 我应该如何编写我的代码来处理这种情况并从上一次执行代码的地方继续执行?
One possible approach i could think of is to catch the exeception. 我可能想到的一种可能的方法是捕捉这种观念。 and redo the logic again.
并重新执行逻辑。
While(NetworkProblem){ 而(NetworkProblem){
NetworkProblem = false; NetworkProblem = false; try{
尝试{
//step 1 - Reading info from db //step 2 - storing on class objects //step 3 - updating info //step 4 - connecting to another webserver //step 5 - update info //步骤1-从数据库中读取信息//步骤2-存储在类对象上//步骤3-更新信息//步骤4-连接到另一个Web服务器//步骤5-更新信息
}catch(NetworkgoneException){ NetworkProblem = true; } catch(NetworkgoneException){NetworkProblem = true;
// try to connect again - this again i dont know how long will take. //尝试重新连接-这又一次我不知道要花多长时间。 }
}
} }
In principle your approach seems ok. 原则上,您的方法不错。 Some points to consider:
需要考虑的几点:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.