©
This document uses PHP Chinese website manual Release
(PHP 5 >= 5.1.0)
ErrorException::getSeverity — 获取异常的严重程度
返回异常的严重程度。
此函数没有参数。
返回异常的严重级别。
Example #1 ErrorException::getSeverity() 例子
<?php
try {
throw new ErrorException ( "Exception message" , 0 , 75 );
} catch( ErrorException $e ) {
echo "This exception severity is: " . $e -> getSeverity ();
}
?>
以上例程的输出类似于:
This exception severity is: 75
[#1] fgaab [2010-03-08 06:38:08]
Try this as replacement for error_reporting(...)
<?php
function exception_error_handler($errno, $errstr, $errfile, $errline ) {
$severity =
1 * E_ERROR |
1 * E_WARNING |
0 * E_PARSE |
0 * E_NOTICE |
0 * E_CORE_ERROR |
0 * E_CORE_WARNING |
0 * E_COMPILE_ERROR |
0 * E_COMPILE_WARNING |
0 * E_USER_ERROR |
0 * E_USER_WARNING |
0 * E_USER_NOTICE |
0 * E_STRICT |
0 * E_RECOVERABLE_ERROR |
0 * E_DEPRECATED |
0 * E_USER_DEPRECATED;
$ex = new ErrorException($errstr, 0, $errno, $errfile, $errline);
if (($ex->getSeverity() & $severity) != 0) {
throw $ex;
}
}
set_error_handler("exception_error_handler");
?>