From 0ae8f5fcb28474e21864102b3ced21a2b4010901 Mon Sep 17 00:00:00 2001 From: tjhunt Date: Thu, 7 May 2009 05:38:35 +0000 Subject: [PATCH] exceptions: MDL-16175 more careful decision whether to use _print_normal/early_error. 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 | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/lib/setuplib.php b/lib/setuplib.php index 3e24758a97..3e47966f98 100644 --- a/lib/setuplib.php +++ b/lib/setuplib.php @@ -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); } } -- 2.39.5