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!
This commit is contained in:
tjhunt
2009-05-07 05:38:35 +00:00
parent 576e101aa3
commit 0ae8f5fcb2
+24 -10
View 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);
$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) {
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);
}
$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);
}
}