Skip to content

Commit

Permalink
Added try/catch block into ErrorHandler::handleException() to gracefu…
Browse files Browse the repository at this point in the history
…lly show Exceptions raised during exception handling. Fixes #1707
  • Loading branch information
Thomas Ploch authored and markstory committed May 17, 2011
1 parent 6289f20 commit 085c621
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions lib/Cake/Error/ErrorHandler.php
Expand Up @@ -107,22 +107,32 @@ class ErrorHandler {
* @see http://php.net/manual/en/function.set-exception-handler.php
*/
public static function handleException(Exception $exception) {
$config = Configure::read('Exception');
if (!empty($config['log'])) {
$message = sprintf("[%s] %s\n%s",
get_class($exception),
$exception->getMessage(),
$exception->getTraceAsString()
try {
$config = Configure::read('Exception');
if (!empty($config['log'])) {
$message = sprintf("[%s] %s\n%s",
get_class($exception),
$exception->getMessage(),
$exception->getTraceAsString()
);
CakeLog::write(LOG_ERR, $message);
}
$renderer = $config['renderer'];
if ($renderer !== 'ExceptionRenderer') {
list($plugin, $renderer) = pluginSplit($renderer, true);
App::uses($renderer, $plugin . 'Error');
}
$error = new $renderer($exception);
$error->render();
} catch (Exception $e) {
$message = $e->getMessage()."\nCall Stack:\n".$e->getTraceAsString();
ErrorHandler::handleError(
E_ERROR,
$message,
$e->getFile(),
$e->getLine()
);
CakeLog::write(LOG_ERR, $message);
}
$renderer = $config['renderer'];
if ($renderer !== 'ExceptionRenderer') {
list($plugin, $renderer) = pluginSplit($renderer, true);
App::uses($renderer, $plugin . 'Error');
}
$error = new $renderer($exception);
$error->render();
}

/**
Expand Down Expand Up @@ -178,6 +188,7 @@ public static function handleError($code, $description, $file = null, $line = nu
* @return array Array of error word, and log location.
*/
protected static function _mapErrorCode($code) {
$error = $log = null;
switch ($code) {
case E_PARSE:
case E_ERROR:
Expand Down

0 comments on commit 085c621

Please sign in to comment.