From aaebf97bee13e1dd15739baa58a6ea9069fe220b Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Sat, 13 Mar 2010 00:00:47 +1300 Subject: [PATCH] Enhance the exception handler to display a forward trace --- inc/always.php | 9 +++++++-- inc/always.php.in | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/inc/always.php b/inc/always.php index 253a3ebb..273d522e 100644 --- a/inc/always.php +++ b/inc/always.php @@ -14,8 +14,13 @@ unset($session); unset($request); unset($dbconn); unset($_awl_dbconn); unset($in // An ultra-simple exception handler to catch errors that occur // before we get a more functional exception handler in place... -function early_exception_handler($exception) { - echo "Uncaught early exception: ", $exception->getMessage(), "\n"; +function early_exception_handler($e) { + echo "Uncaught early exception: ", $e->getMessage(), "\nAt line ", $e->getLine(), " of ", $e->getFile(), "\n"; + + $trace = array_reverse($e->getTrace()); + foreach( $trace AS $k => $v ) { + printf( "=====================================================\n%s[%d] %s%s%s()\n", $v['file'], $v['line'], (isset($v['class'])?$v['class']:''), (isset($v['type'])?$v['type']:''), (isset($v['function'])?$v['function']:'') ); + } } set_exception_handler('early_exception_handler'); diff --git a/inc/always.php.in b/inc/always.php.in index c111cb8e..71c2138d 100644 --- a/inc/always.php.in +++ b/inc/always.php.in @@ -14,8 +14,13 @@ unset($session); unset($request); unset($dbconn); unset($_awl_dbconn); unset($in // An ultra-simple exception handler to catch errors that occur // before we get a more functional exception handler in place... -function early_exception_handler($exception) { - echo "Uncaught early exception: ", $exception->getMessage(), "\n"; +function early_exception_handler($e) { + echo "Uncaught early exception: ", $e->getMessage(), "\nAt line ", $e->getLine(), " of ", $e->getFile(), "\n"; + + $trace = array_reverse($e->getTrace()); + foreach( $trace AS $k => $v ) { + printf( "=====================================================\n%s[%d] %s%s%s()\n", $v['file'], $v['line'], (isset($v['class'])?$v['class']:''), (isset($v['type'])?$v['type']:''), (isset($v['function'])?$v['function']:'') ); + } } set_exception_handler('early_exception_handler');