From 8df1407a11df3e5a8c33c6fae1c522707aefccf3 Mon Sep 17 00:00:00 2001 From: xue <> Date: Fri, 24 Mar 2006 23:06:31 +0000 Subject: Enhanced error context display when a PHP error occurs. --- framework/Exceptions/TErrorHandler.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'framework/Exceptions/TErrorHandler.php') diff --git a/framework/Exceptions/TErrorHandler.php b/framework/Exceptions/TErrorHandler.php index 23644fb7..4b42491e 100644 --- a/framework/Exceptions/TErrorHandler.php +++ b/framework/Exceptions/TErrorHandler.php @@ -207,8 +207,21 @@ class TErrorHandler extends TModule */ protected function displayException($exception) { - $lines=file($exception->getFile()); + $fileName=$exception->getFile(); $errorLine=$exception->getLine(); + if($exception instanceof TPhpErrorException) + { + // if PHP exception, we want to show the 2nd stack level context + // because the 1st stack level is of little use (it's in error handler) + $trace=$exception->getTrace(); + if(isset($trace[0]) && isset($trace[0]['file']) && isset($trace[0]['line'])) + { + $fileName=$trace[0]['file']; + $errorLine=$trace[0]['line']; + } + } + $lines=file($fileName); + $beginLine=$errorLine-self::SOURCE_LINES>=0?$errorLine-self::SOURCE_LINES:0; $endLine=$errorLine+self::SOURCE_LINES<=count($lines)?$errorLine+self::SOURCE_LINES:count($lines); @@ -227,7 +240,7 @@ class TErrorHandler extends TModule $tokens=array( '%%ErrorType%%' => get_class($exception), '%%ErrorMessage%%' => htmlspecialchars($exception->getMessage()), - '%%SourceFile%%' => htmlspecialchars($exception->getFile()).' ('.$exception->getLine().')', + '%%SourceFile%%' => htmlspecialchars($fileName).' ('.$errorLine.')', '%%SourceCode%%' => $source, '%%StackTrace%%' => htmlspecialchars($exception->getTraceAsString()), '%%Version%%' => $_SERVER['SERVER_SOFTWARE'].' PRADO/'.Prado::getVersion(), -- cgit v1.2.3