Advertisement
P22DX

exception.php

Aug 13th, 2020
1,160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.32 KB | None | 0 0
  1. <?php
  2.  
  3. function get_zero()
  4. {
  5.     $res = rand(0, 9);
  6.     if($res != 0) throw new \Exception('not a zero');
  7.     return 'got a zero';
  8. }
  9.  
  10. start:
  11.  
  12. try {
  13.     echo get_zero(), PHP_EOL;
  14. } catch(\Exception $e)
  15. {
  16.     echo $e->getMessage(), PHP_EOL;
  17.     goto start;
  18. }
  19. echo 'php will start over and over until exception not thrown', PHP_EOL;
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement