public function handleError($sender, $param)
{
static $handling = false;
// We need to restore error and exception handlers,
// because within error and exception handlers, new errors and exceptions
// cannot be handled properly by PHP
restore_error_handler();
restore_exception_handler();
// ensure that we do not enter infinite loop of error handling
if ($handling) {
$this->handleRecursiveError($param);
} else {
$handling = true;
if (($response = $this->getResponse()) !== null) {
$response->clear();
}
if (!headers_sent()) {
header('Content-Type: text/html; charset=UTF-8');
}
if ($param instanceof THttpException) {
$this->handleExternalError($param->getStatusCode(), $param);
} else {
if ($this->getApplication()->getMode() === TApplicationMode::Debug) {
$this->displayException($param);
} else {
$this->handleExternalError(500, $param);
}
}
}
}