用户操作
[即时聊天] [发私信] [加为好友]
xiaolei1982
xiaolei1982的公告
这两天总结了一些东西,写得有点乱,里面有很多是自己认为的,所以会有不对的地方,希望阅读的朋友如果看到有错误的话请给予指出,以免误人子弟。
最近评论
yang_ming:不错,收藏之
seamon0627:JavaScript出错最难调试!
但闰月和弄÷:评论
#sz_haitao 发表于2008-10-03 16:16:53 IP: 121.15.117.*
js如此灵活,是福是祸?



肯定是祸了
servaywong:不错 收藏了
断弦:看君一帖子,胜读十年书,非常非常之感谢!!
文章分类
收藏
    相册
    我的相册
    存档
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 php自定义异常类(根据fleaphp摘抄出来,非常有借鉴作用)收藏

    新一篇: javascript关于面向对象的总结 | 旧一篇: jsp页面传递

    <?php
    echo <<<EOT
    <script language="javascript" type="text/javascript">
    function switch_filedesc(id)
    {
        var el = document.getElementById(id);
        if (el.style.display == 'none') {
            el.style.display = 'block';
        } else {
            el.style.display = 'none';
        }
    }

    function copytextToClipboard(txt)
    {
        if (window.clipboardData) {
            window.clipboardData.clearData();
            window.clipboardData.setData('Text', txt);
        }
    }

    </script>
    EOT;

    class MyException extends Exception
    {
        // 重定义构造器使 message 变为必须被指定的属性
        public function __construct($message, $code = 0) {
            // 自定义的代码

            // 确保所有变量都被正确赋值
            parent::__construct($message, $code);
        }

        // 自定义字符串输出的样式 */
        public function __toString() {
            return __CLASS__ . ": [{$this->code}]: {$this->message}\n";
        }

        public function customFunction() {
            echo "A Custom function for this type of exception\n";
        }
    }

    class TestException
    {
        public $var;
        const THROW_NONE    = 0;
        const THROW_CUSTOM  = 1;
        const THROW_DEFAULT = 2;

        function __construct() {
        }
        
        function aa($d)
        {
            throw new MyException('1 is an invalid parameter', 5);
        }
    }
        try{
            $dd=new TestException();
            $dd->aa("aaa");
        }
        catch (MyException $ex) {
           __error_dump_trace($ex);
    }

    function __error_dump_trace($ex)
    {
        echo '<strong>Exception: </strong>' . get_class($ex) . "<br />\n";
        if ($ex->getMessage() != '') {
            echo '<strong>Message: </strong>' . $ex->getMessage() . "<br />\n";
        }
        echo "<br />\n";

        $trace = $ex->getTrace();
        $ix = count($trace);
        print_r($trace);
        foreach ($trace as $point) {
            $file = isset($point['file']) ? $point['file'] : null;
            $line = isset($point['line']) ? $point['line'] : null;
            $id = md5("{$file}({$line})");
            $function = isset($point['class']) ? "{$point['class']}::{$point['function']}" : $point['function'];

            $args = array();
            if (is_array($point['args']) && count($point['args']) > 0) {
                foreach ($point['args'] as $arg) {
                    switch (gettype($arg)) {
                    case 'array':
                        $args[] = 'array(' . count($arg) . ')';
                        break;
                    case 'resource':
                        $args[] = gettype($arg);
                        break;
                    case 'object':
                        $args[] = get_class($arg);
                        break;
                    case 'string':
                        if (strlen($arg) > 30) {
                            $arg = substr($arg, 0, 27) . ' ...';
                        }
                        $args[] = "'{$arg}'";
                        break;
                    default:
                        $args[] = $arg;
                    }
                }
            }
            $args = implode(", ", $args);

            echo <<<EOT
    <hr />
    <strong>Filename:</strong> <a href="javascript:switch_filedesc('{$id}');">{$file} [{$line}]</a><br />
    #{$ix} {$function}($args)
    <div id="{$id}" class="filedesc" style="display: none;">
    ARGS:
    EOT;

           dump($point['args']);
            echo "SOURCE CODE: <br />\n";
            echo __error_show_source ($file, $line);
            echo "\n</div>\n";
            echo "<br />\n";
            $ix--;
        }
    }
     
    function __error_show_source($file, $line, $prev = 10, $next = 10)
    {
        if (!(file_exists($file) && is_file($file))) {
            return '';
        }

        $data = file($file);
        $count = count($data) - 1;

        //count which lines to display
        $start = $line - $prev;
        if ($start < 1) {
            $start = 1;
        }
        $end = $line + $next;
        if ($end > $count) {
            $end = $count + 1;
        }

        //displaying
        $out = '<table cellspacing="0" cellpadding="0">';

        for ($x = $start; $x <= $end; $x++) {
            $out .= "  <tr>\n";
            if ($line != $x) {
                $out .= "    <td class=\"line-num\">";
            } else {
                $out .= "    <td class=\"line-num-break\">";
            }
            $out .= str_repeat('&nbsp;', (strlen($end) - strlen($x)) + 1);
            $out .= $x;
            $out .= "&nbsp;</td>\n";

            $out .= "    <td class=\"source\">&nbsp;";
            $out .= t($data[$x - 1]);
            $out .= "</td>\n  </tr>\n";
        }
        $out .= "</table>\n";
        return $out;
    }

    function t($text)
    {
        return nl2br(str_replace(' ', '&nbsp;', htmlspecialchars($text)));
    }

    function dump($vars, $label = '', $return = false)
    {
        if (ini_get('html_errors')) {
            $content = "<pre>\n";
            if ($label != '') {
                $content .= "<strong>{$label} :</strong>\n";
            }
            $content .= htmlspecialchars(print_r($vars, true));
            $content .= "\n</pre>\n";
        } else {
            $content = $label . " :\n" . print_r($vars, true);
        }
        if ($return) { return $content; }
        echo $content;
        return null;
    }
    ?>

    发表于 @ 2008年07月14日 11:00:00|评论(loading...)|编辑|收藏

    新一篇: javascript关于面向对象的总结 | 旧一篇: jsp页面传递

    评论

    #xiaolei1982 发表于2008-07-14 11:02:53  IP: 124.135.7.*
    粘贴就可运行,大家可以看看效果
    发表评论  


    登录
    Csdn Blog version 3.1a
    Copyright © xiaolei1982