Added support for previous exceptions

PHP supports exception stacks since 5.3 so we should use it.
Also Errorhandler is now able to display the stack: #297
This commit is contained in:
Carsten Brandt
2013-05-26 04:38:13 +02:00
parent 0ef40b28d1
commit 689080519e
9 changed files with 82 additions and 11 deletions

View File

@@ -48,6 +48,10 @@ class ErrorHandler extends Component
* @var string the path of the view file for rendering exceptions and errors call stack element.
*/
public $callStackItemView = '@yii/views/errorHandler/callStackItem.php';
/**
* @var string the path of the view file for rendering previous exceptions.
*/
public $previousExceptionView = '@yii/views/errorHandler/previousException.php';
/**
* @var \Exception the exception that is being handled currently.
*/
@@ -160,6 +164,24 @@ class ErrorHandler extends Component
return '<a href="http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#' . (int)$statusCode .'" target="_blank">HTTP ' . (int)$statusCode . ' &ndash; ' . $statusDescription . '</a>';
}
/**
* Renders the previous exception stack for a given Exception.
* @param \Exception $exception the exception whose precursors should be rendered.
* @return string HTML content of the rendered previous exceptions.
* Empty string if there are none.
*/
public function renderPreviousExceptions($exception)
{
if (($previous = $exception->getPrevious()) === null) {
return '';
}
$view = new View();
return $view->renderFile($this->previousExceptionView, array(
'exception' => $previous,
'previousHtml' => $this->renderPreviousExceptions($previous),
), $this);
}
/**
* Renders a single call stack element.
* @param string $file name where call has happened.

View File

@@ -103,7 +103,7 @@ class HttpException extends UserException
if (isset($httpCodes[$this->statusCode])) {
return $httpCodes[$this->statusCode];
} else {
return \Yii::t('yii', 'Error');
return 'Error';
}
}
}