* @return void Terminates script, does not return!
*/
function error($message, $link='') {
- global $UNITTEST;
+ global $UNITTEST, $OUTPUT;
// If unittest running, throw exception instead
if (!empty($UNITTEST->running)) {
throw new moodle_exception('notlocalisederrormessage', 'error', $link, $message);
}
- _print_normal_error('notlocalisederrormessage', 'error', $message, $link, debug_backtrace(), null, true); // show debug warning
+ list($message, $moreinfourl, $link) = prepare_error_message('notlocalisederrormessage', 'error', $link, $message);
+ $OUTPUT->fatal_error($message, $moreinfourl, $link, debug_backtrace(), null, true); // show debug warning
+ die;
}
/**
* Default exception handler, uncought exceptions are equivalent to using print_error()
+ *
+ * @param Exception $ex
+ * @param boolean $isupgrade
+ * @param string $plugin
+ * Does not return. Terminates execution.
*/
-function default_exception_handler($ex) {
+function default_exception_handler($ex, $isupgrade = false, $plugin = null) {
global $CFG, $DB, $SCRIPT;
// detect active db transactions, rollback and log as error
list($message, $moreinfourl, $link) = prepare_error_message($errorcode, $module, $link, $a);
+ if ($isupgrade) {
+ // First log upgrade error
+ upgrade_log(UPGRADE_LOG_ERROR, $plugin, 'Exception: ' . get_class($ex), $message, $backtrace);
+
+ // Always turn on debugging - admins need to know what is going on
+ $CFG->debug = DEBUG_DEVELOPER;
+ }
+
if ($earlyerror) {
// Error found before setup.php finished
_print_early_error($message, $backtrace, $debuginfo);
/**
* upgrade logging functions
*/
-function upgrade_handle_exception($ex, $plugin=null) {
- global $CFG;
-
- if ($ex instanceof moodle_exception) {
- $details = get_string($ex->errorcode, $ex->module, $ex->a)."<br />debugging:".$ex->debuginfo;
- } else {
- $details = get_string('generalexceptionmessage', 'error', $ex->getMessage());
- }
- $info = "Exception: ".get_class($ex);
- $backtrace = $ex->getTrace();
- $place = array('file'=>$ex->getFile(), 'line'=>$ex->getLine(), 'exception'=>get_class($ex));
- array_unshift($backtrace, $place);
-
- /// first log upgrade error
- upgrade_log(UPGRADE_LOG_ERROR, $plugin, $info, $details, $backtrace);
-
- // always turn on debugging - admins need to know what is going on
- $CFG->debug = DEBUG_DEVELOPER;
-
- // now print the exception info as usually
- if ($ex instanceof moodle_exception) {
- _print_normal_error($ex->errorcode, $ex->module, $ex->a, $ex->link, $backtrace, $ex->debuginfo);
- } else {
- _print_normal_error('generalexceptionmessage', 'error', $ex->getMessage(), '', $backtrace);
- }
-
- die; // not reached
+function upgrade_handle_exception($ex, $plugin = null) {
+ default_exception_handler($ex, true, $plugin);
}
/**