Search code examples
phploopserror-handlingskip

Skipping errors in a loop? (PHP)


I have a loop where the code loops and in every loop it connects to different server and then makes MySQL query. However sometimes one of the loops/queries cannot reach to the end and all the code breaks. Is there a way where if the loop gives error then skip the processes / move to next loop?


Solution

  • As stated in the comments above, the correct way to do this is within a try...catch block.

    To learn more about these, you can read about them here.

    Thanks @Paul.