Paste_Image.png
ErrorException.php
<?php
function exception_error_handler($errno, $errstr, $errfile, $errline)
{
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
set_error_handler('exception_error_handler');
try {
echo gettype();
} catch (Exception $e) {
$e->getMessage();
}
ErrorToException.php
<?php
class ErrorToException extends Exception
{
public static function handle($errno, $errstr)
{
throw new self($errstr, $errno);
}
}
//set_error_handler(array('ErrorToException', 'handle'));
set_error_handler(array('ErrorToException', 'handle'), E_USER_WARNING | E_WARNING);
try {
echo $test;
echo "<hr/>";
gettype();
echo "<hr/>";
//trigger_error('test', E_USER_WARNING);
} catch (Exception $e) {
echo '异常<br/>';
echo $e->getMessage();
}
?>
Paste_Image.png
网友评论