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 = 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
}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:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.