[PHP错误异常]①④--记录和发送异常信息

2017-09-15  本文已影响12人  子木同
<?php

class LoginException extends Exception
{

    public function __construct($message = null, $code = 0)
    {
        parent::__construct($message, $code);
        //error_log($this->getMessage(), 3, 'D:/error/testLoginException.log');
        error_log($this->getTraceAsString(), 3, 'D:/error/testLoginException.log');
    }
}

try {
    $link = @mysql_connect('localhost', 'dfdfdf', 'fgfgfgf');
    if (!$link) {
        throw new LoginException('数据库连接失败');
    }

} catch (LoginException $e) {
    echo $e->getMessage();
}
Paste_Image.png Paste_Image.png
上一篇 下一篇

猜你喜欢

热点阅读