blessing-skin-server/libraries/E.class.php

41 lines
1012 B
PHP
Raw Normal View History

2016-03-27 11:38:27 +08:00
<?php
/**
* @Author: printempw
* @Date: 2016-03-27 11:04:14
* @Last Modified by: printempw
* @Last Modified time: 2016-03-27 11:36:57
*/
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;
header('Content-type: application/json; charset=utf-8');
exit(json_encode($exception));
}
private function showErrorPage() {
$message = $this->message;
$code = $this->code;
require BASE_DIR."/templates/error.tpl.php";
exit;
}
}