예제 #1
0
/**
 * Print an error page displaying an error message.
 * 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!
 */
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);
    $OUTPUT->fatal_error($message, $moreinfourl, $link, debug_backtrace(), null, true);
    // show debug warning
    die;
}
예제 #2
0
/**
 * Abort execution, displaying an error message.
 *
 * @param string $errorcode The name of the language string containing the error message.
 *      Normally this should be in the error.php lang file.
 * @param string $module The language file to get the error message from.
 * @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.
 * @param object $a Extra words and phrases that might be required in the error string
 * @return void terminates script, does not return!
 */
function print_error($errorcode, $module = 'error', $link = '', $a = null)
{
    global $OUTPUT, $UNITTEST;
    // Errors in unit test become exceptions, so you can unit test code that might call print_error().
    if (!empty($UNITTEST->running)) {
        throw new moodle_exception($errorcode, $module, $link, $a);
    } else {
        // It is really bad if library code calls print_error when output buffering
        // is on.
        while (ob_get_level() > 0) {
            ob_end_clean();
        }
    }
    list($message, $moreinfourl, $link) = prepare_error_message($errorcode, $module, $link, $a);
    if (is_stacktrace_during_output_init(debug_backtrace())) {
        echo bootstrap_renderer::early_error($message, $moreinfourl, $link, debug_backtrace());
    } else {
        echo $OUTPUT->fatal_error($message, $moreinfourl, $link, debug_backtrace());
    }
    exit(1);
    // General error code
}