From ac580cdff89772afac7ebc6182efc625b9876a7b Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Tue, 1 Jul 2008 22:13:25 -0400 Subject: [PATCH] Adding a global exception handler BSExceptionHandler * ExceptionHandler.php: New file * App.php: set_exception_handler() to use BSExceptionHandler --- App.php | 3 +- CHANGES | 1 + ExceptionHandler.php | 164 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 ExceptionHandler.php diff --git a/App.php b/App.php index 7318fcc..5e0fce7 100644 --- a/App.php +++ b/App.php @@ -51,7 +51,8 @@ if ((bool)ini_get('register_globals') === true) } } -require_once(ISSO . '/Functions.php'); +require_once ISSO . '/ExceptionHandler.php'; +set_exception_handler(array('BSExceptionHandler', 'handle')); /** * Application Class diff --git a/CHANGES b/CHANGES index 7493747..edc044a 100644 --- a/CHANGES +++ b/CHANGES @@ -13,3 +13,4 @@ - New: Add BSTemplate::$globalVars to be substituted into every template - Change: BSTemplate will better detect parse errors in nested templates in BSTemplate::evaluate() - Change: ApiException will now report all of its messages in ::getMessage() +- New: Added BSExceptionHandler to handle all exceptions in a pretty fasion diff --git a/ExceptionHandler.php b/ExceptionHandler.php new file mode 100644 index 0000000..bff2812 --- /dev/null +++ b/ExceptionHandler.php @@ -0,0 +1,164 @@ +getTrace(); + $framework = false; + foreach ($trace as $i => $frame) + { + if (!isset($frame['file'])) + { + continue; + } + if (strpos($frame['file'], ISSO) !== false || substr($frame['class'], 0, 2) == 'BS') + { + $framework = true; + break; + } + } +?> + + + + Uncaught Exception + + + + + + +
+

Uncaught Exception

+ +

+ An exception was encountered during the exection of this program. Because the program could not recover + from this error it terminated prematurely. Please contact a system administrator if this problem persists. +

+ +
+ +

Time:

+ +

Context:

+ +

Class:

+ +

Message: getMessage() ?>

+ +

+ Stack Trace:
+

+getTraceAsString();
+			echo (BSApp::get_debug() ? $trace : str_replace(getcwd(), '', $trace));
+?>
+		
+

+
+ + + +