文字
分享

ErrorException::getSeverity

(PHP 5 >= 5.1.0)

ErrorException::getSeverity获取异常的严重程度

说明

final public int ErrorException::getSeverity ( void )

返回异常的严重程度。

参数

此函数没有参数。

返回值

返回异常的严重级别。

范例

Example #1 ErrorException::getSeverity() 例子

<?php
try {
    throw new 
ErrorException ( "Exception message" 0 75 );
} catch(
ErrorException $e ) {
    echo 
"This exception severity is: "  $e -> getSeverity ();
}
?>

以上例程的输出类似于:

1

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 =
            
E_ERROR |
            
E_WARNING 
            
E_PARSE |
            
E_NOTICE |
            
E_CORE_ERROR |
            
E_CORE_WARNING |
            
E_COMPILE_ERROR |
            
E_COMPILE_WARNING 
            
E_USER_ERROR |
            
E_USER_WARNING |
            
E_USER_NOTICE |
            
E_STRICT |
            
E_RECOVERABLE_ERROR |
            
E_DEPRECATED |
            
E_USER_DEPRECATED;
        
$ex = new ErrorException($errstr0$errno$errfile$errline);
        if ((
$ex->getSeverity() & $severity) != 0) {
                       throw 
$ex;
                }
    }
    
set_error_handler("exception_error_handler");
?>