美文网首页
[PHP错误异常]①④--记录和发送异常信息

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

作者: 子木同 | 来源:发表于2017-09-15 11:34 被阅读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

相关文章

网友评论

      本文标题:[PHP错误异常]①④--记录和发送异常信息

      本文链接:https://www.haomeiwen.com/subject/vdjssxtx.html