Property 'CErrorHandler::exception' added to store current handling exception instance

This commit is contained in:
Paul Klimov
2013-10-02 12:43:54 +03:00
parent 8f0619e864
commit d885fcbba1

View File

@@ -48,6 +48,7 @@ Yii::import('CHtml',true);
* {@link CApplication::getErrorHandler()}.
*
* @property array $error The error details. Null if there is no error.
* @property Exception|null $exception exception instance. Null if there is no exception.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @package system.base
@@ -82,6 +83,7 @@ class CErrorHandler extends CApplicationComponent
public $errorAction;
private $_error;
private $_exception;
/**
* Handles the exception/error event.
@@ -150,6 +152,15 @@ class CErrorHandler extends CApplicationComponent
return $this->_error;
}
/**
* Returns the instance of the exception that is currently being handled.
* @return Exception|null exception instance. Null if there is no exception.
*/
public function getException()
{
return $this->_exception;
}
/**
* Handles the exception.
* @param Exception $exception the exception captured
@@ -186,6 +197,7 @@ class CErrorHandler extends CApplicationComponent
unset($trace[$i]['object']);
}
$this->_exception=$exception;
$this->_error=$data=array(
'code'=>($exception instanceof CHttpException)?$exception->statusCode:500,
'type'=>get_class($exception),
@@ -200,7 +212,7 @@ class CErrorHandler extends CApplicationComponent
if(!headers_sent())
header("HTTP/1.0 {$data['code']} ".$this->getHttpHeader($data['code'], get_class($exception)));
$this->renderException($exception);
$this->renderException();
}
else
$app->displayException($exception);
@@ -262,6 +274,7 @@ class CErrorHandler extends CApplicationComponent
default:
$type = 'PHP error';
}
$this->_exception=null;
$this->_error=array(
'code'=>500,
'type'=>$type,
@@ -323,10 +336,10 @@ class CErrorHandler extends CApplicationComponent
/**
* Renders the exception information.
* This method will display information from current {@link error} value.
* @param Exception $exception exception object.
*/
protected function renderException(Exception $exception)
protected function renderException()
{
$exception=$this->getException();
if($exception instanceof CHttpException || !YII_DEBUG)
$this->renderError();
else