[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();
}
![](https://img.haomeiwen.com/i2953340/ab8e1c453fc67afa.png)
![](https://img.haomeiwen.com/i2953340/0a14eaf3f0f0368e.png)