2016-03-27 11:38:27 +08:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @Author: printempw
|
|
|
|
* @Date: 2016-03-27 11:04:14
|
|
|
|
* @Last Modified by: printempw
|
2016-04-03 15:56:16 +08:00
|
|
|
* @Last Modified time: 2016-04-03 15:53:59
|
2016-03-27 11:38:27 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
class E extends Exception
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Custom error handler
|
|
|
|
*
|
|
|
|
* @param string $message
|
|
|
|
* @param integer $code
|
|
|
|
* @param boolean $render, to show a error page
|
|
|
|
*/
|
|
|
|
function __construct($message = "Error occured.", $code = -1, $render = false) {
|
|
|
|
parent::__construct($message, $code);
|
|
|
|
if ($render) {
|
|
|
|
$this->showErrorPage();
|
|
|
|
} else {
|
|
|
|
$this->showErrorJson();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function showErrorJson() {
|
|
|
|
$exception['errno'] = $this->code;
|
|
|
|
$exception['msg'] = $this->message;
|
2016-04-02 22:53:55 +08:00
|
|
|
@header('Content-type: application/json; charset=utf-8');
|
2016-03-27 11:38:27 +08:00
|
|
|
exit(json_encode($exception));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function showErrorPage() {
|
|
|
|
$message = $this->message;
|
|
|
|
$code = $this->code;
|
2016-04-03 15:56:16 +08:00
|
|
|
require dirname(dirname(__FILE__))."/templates/error.tpl.php";
|
2016-03-27 11:38:27 +08:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|