写了一个错误处理类

PHP 的 try – catch 总有很多东西抓不住。我还是自己写了一个。

<?php
/**
* 错误处理类
*
* 用法:
* ErrorHandler::begin();
* //要捕获错误的代码
* $errors = ErrorHandler::end();
* 可以嵌套使用。
*
* 本类只捕获错误,不捕获异常。如需捕获异常,请使用try-catch。
*
*
* @author XieZhenye
*/
class ErrorHandler{
    private static $error = array();
    function begin(){
        set_error_handler(array(__CLASS__, ‘_errorHandler’));
        array_push(self::$error, array());
    }

    function _errorHandler($errno, $errstr, $errfile, $errline){
        if($errno == E_STRICT)
            return;
        
        $errInfo = array(‘errno’=>$errno, ‘errstr’=>$errstr,
                    ‘errfile’=>$errfile, ‘errline’=>$errline);
        
        array_push(self::$error[count(self::$error)-1], $errInfo);
    }

    function end(){
        restore_error_handler();
        $ret = end(self::$error);
        array_pop(self::$error);
        return $ret;
    }
}

?>

4 thoughts on “写了一个错误处理类

  1. psdshow October 7, 2006 / 3:41 am

    看了这些
    我决定不再写程序le
    我不知道什么时候才能达到这个水平

  2. 金手指 September 4, 2006 / 1:44 pm

    我的邮箱地址是sunsky.li@gmail.com

  3. 虎虎 September 2, 2006 / 5:50 pm

    华丽地复活

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s