Hello.

Please tell me how to work with exceptions in PHP? I used to work with Python, and everything was just there:

try: ... except: ... 

My script receives the API data in the JSON object, I need to make a condition that will check if the json object returns nothing - wait 10 seconds and try again.

In Python, this was solved very easily:

 try: url = "http://site.......... with urlopen(url) as response: ..... except: time.sleep(10) 

How to make such an exception in PHP, I do not fully understand.

I would be grateful for any help!

  • And where do you have to "try again" on python? - vp_arth
  • @vp_arth is more likely not to "try again", but to go through the cycle again. - Muday

1 answer 1

PHP exception handling is not much different from other C-like languages.

 try { $url = ""; // some code } catch (\Exception $e) { // (\Throwable $e) в php7 sleep(10); } 
  • not C ++ like, but C like - darkwoolf
  • How do your exceptions are handled in C itself? - vp_arth