php - try, catch, and retry

后端 未结 6 2127
一向
一向 2020-12-23 19:49

Sometimes my code breaks and it is out of my control

How would I do the following?

try {
//do my stuff
}
catch {
//sleep and try again
}
         


        
6条回答
  •  既然无缘
    2020-12-23 20:20

    Here is an easy algorithm:

        do{
            try {
                $tryAgain = false;
                /* Do everything that throws error here */
    
            }
            catch(Exception $e) {
                $tryAgain = true;
                /* Do error reporting/archiving/logs here */
    
            }
        } while($tryAgain);
    

提交回复
热议问题