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