From: Petr Skoda Date: Fri, 30 Oct 2009 13:12:45 +0000 (+0000) Subject: MDL-20677 exception used in error() instead of print&die - this helps a lot when... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=a8ab8de9595cdfe8adde1dd4b55986805075352f;p=moodle.git MDL-20677 exception used in error() instead of print&die - this helps a lot when you need custom default exception handlers; it also reduces duplication in code --- diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index 4db9b34a84..731ae5e97a 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -574,27 +574,18 @@ function get_current_group($courseid, $full = false) { /** - * Print an error page displaying an error message. + * Inndicates fatal error. This function was originally printing the + * error message directly, since 2.0 it is throwing exception instead. + * The error printing is handled in default exception hadnler. + * * Old method, don't call directly in new code - use print_error instead. * - * @global object * @param string $message The message to display to the user about the error. * @param string $link The url where the user will be prompted to continue. If no url is provided the user will be directed to the site index page. - * @return void Terminates script, does not return! + * @return void, always throws moodle_exception */ function error($message, $link='') { - global $UNITTEST, $OUTPUT; - - // If unittest running, throw exception instead - if (!empty($UNITTEST->running)) { - // Errors in unit test become exceptions, so you can unit test - // code that might call error(). - throw new moodle_exception('notlocalisederrormessage', 'error', $link, $message); - } - - list($message, $moreinfourl, $link) = prepare_error_message('notlocalisederrormessage', 'error', $link, $message); - echo $OUTPUT->fatal_error($message, $moreinfourl, $link, debug_backtrace(), null, true); // show debug warning - die; + throw new moodle_exception('notlocalisederrormessage', 'error', $link, $message); }