error_2_exception_001.phpt 924 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. --TEST--
  2. ZE2 errors caught as exceptions
  3. --FILE--
  4. <?php
  5. class MyException extends Exception {
  6. function __construct($_errno, $_errmsg) {
  7. $this->errno = $_errno;
  8. $this->errmsg = $_errmsg;
  9. }
  10. function getErrno() {
  11. return $this->errno;
  12. }
  13. function getErrmsg() {
  14. return $this->errmsg;
  15. }
  16. }
  17. function ErrorsToExceptions($errno, $errmsg) {
  18. throw new MyException($errno, $errmsg);
  19. }
  20. set_error_handler("ErrorsToExceptions");
  21. // make sure it isn't catching exceptions that weren't
  22. // thrown...
  23. try {
  24. } catch (MyException $exception) {
  25. echo "There was an exception: " . $exception->getErrno() . ", '" . $exception->getErrmsg() . "'\n";
  26. }
  27. try {
  28. trigger_error("I will become an exception", E_USER_ERROR);
  29. } catch (MyException $exception) {
  30. echo "There was an exception: " . $exception->getErrno() . ", '" . $exception->getErrmsg() . "'\n";
  31. }
  32. ?>
  33. --EXPECT--
  34. There was an exception: 256, 'I will become an exception'