Guest User

Untitled

a guest
Aug 18th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. Throwing exception within exception handler
  2. <?php
  3.  
  4. class ExceptionHandler
  5. {
  6. private $rethrow;
  7. public function __construct()
  8. {
  9. set_exception_handler(array($this, 'handler'));
  10. }
  11. public function handler($exception)
  12. {
  13. echo "cleaning up.n";
  14. $this->rethrow = $exception;
  15. }
  16. public function __destruct()
  17. {
  18. if ($this->rethrow) throw $this->rethrow;
  19. }
  20. }
  21.  
  22. $handler = new ExceptionHandler;
  23.  
  24. throw new Exception();
  25.  
  26. [29-Oct-2011 xx:32:25] PHP Fatal error: Uncaught exception 'Exception' in /.../test-exception.php:23
  27. Stack trace:
  28. #0 {main}
  29. thrown in /.../test-exception.php on line 23
  30.  
  31. try {
  32. $foo->doSomethingToCauseException();
  33. } catch (Exception $e) {
  34. error_log($e->getMessage());
  35. throw $e;
  36. }
Add Comment
Please, Sign In to add comment