]> git.mjollnir.org Git - moodle.git/commitdiff
exceptions: MDL-16175 more careful decision whether to use _print_normal/early_error.
authortjhunt <tjhunt>
Thu, 7 May 2009 05:38:35 +0000 (05:38 +0000)
committertjhunt <tjhunt>
Thu, 7 May 2009 05:38:35 +0000 (05:38 +0000)
It is a mistake to use _print_normal_error if the exception was thrown in print_header - we don't want to try to call print_header again!

lib/setuplib.php

index 3e24758a978b7c23f44eda3fc7084b54d1ccdea0..3e47966f98b47525bf5a61b6d281c8ee1b57c6c4 100644 (file)
@@ -69,18 +69,32 @@ function default_exception_handler($ex) {
     $place = array('file'=>$ex->getFile(), 'line'=>$ex->getLine(), 'exception'=>get_class($ex));
     array_unshift($backtrace, $place);
 
-    if ($ex instanceof moodle_exception) {
-        if (!isset($CFG->theme) or !isset($CFG->stylesheets)) {
-            _print_early_error($ex->errorcode, $ex->module, $ex->a, $backtrace, $ex->debuginfo);
-        } else {
-            _print_normal_error($ex->errorcode, $ex->module, $ex->a, $ex->link, $backtrace, $ex->debuginfo);
+    $earlyerror = !isset($CFG->theme) || !isset($CFG->stylesheets);
+    foreach ($backtrace as $stackframe) {
+        if (isset($stackframe['function']) && $stackframe['function'] == 'print_header') {
+            $earlyerror = true;
+            break;
         }
+    }
+
+    if ($ex instanceof moodle_exception) {
+        $errorcode = $ex->errorcode;
+        $module = $ex->module;
+        $a = $ex->a;
+        $link = $ex->link;
+        $debuginfo = $ex->debuginfo;
     } else {
-        if (!isset($CFG->theme) or !isset($CFG->stylesheets)) {
-            _print_early_error('generalexceptionmessage', 'error', $ex->getMessage(), $backtrace);
-        } else {
-            _print_normal_error('generalexceptionmessage', 'error', $ex->getMessage(), '', $backtrace);
-        }
+        $errorcode = 'generalexceptionmessage';
+        $module = 'error';
+        $a = $ex->getMessage();
+        $link = '';
+        $debuginfo = null;
+    }
+
+    if ($earlyerror) {
+        _print_early_error($errorcode, $module, $a, $backtrace, $debuginfo);
+    } else {
+        _print_normal_error($errorcode, $module, $a, $link, $backtrace, $debuginfo);
     }
 }