wecenter学习笔记-全局异常处理

该文是wecenter学习笔记的一部分

全局异常处理

通过设置全局异常回调,将错误定向到500页面

system/aws_app.inc.php#init

set_exception_handler(array('AWS_APP', 'exception_handle'));

...

public static function exception_handle($exception)
{
    $exception_message = "Application error\n------\nMessage: " . $exception->getMessage() . "\nFile: " . $exception->getFile() . "\nLine: " . $exception->getLine() . "\n------\nBuild: " . G_VERSION . " " . G_VERSION_BUILD . "\nPHP Version: " . PHP_VERSION . "\nURI: " . $_SERVER['REQUEST_URI'] . "\nUser Agent: " . $_SERVER['HTTP_USER_AGENT'] . "\nAccept Language: " . $_SERVER['HTTP_ACCEPT_LANGUAGE'] . "\nIP Address: " . fetch_ip() . "\n------\n" . $exception->getTraceAsString();

    show_error($exception_message, $exception->getMessage());
}

system/functions.inc.php

function show_error($exception_message, $error_message = '')
{
    @ob_end_clean();

    if (get_setting('report_diagnostics') == 'Y' AND class_exists('AWS_APP', false))
    {
        AWS_APP::mail()->send('[email protected]', '[' . G_VERSION . '][' . G_VERSION_BUILD . '][' . base_url() . ']' . $error_message, nl2br($exception_message), get_setting('site_name'), 'WeCenter');
    }

    if (isset($_SERVER['SERVER_PROTOCOL']) AND strstr($_SERVER['SERVER_PROTOCOL'], '/1.0') !== false)
    {
        header("HTTP/1.0 500 Internal Server Error");
    }
    else
    {
        header("HTTP/1.1 500 Internal Server Error");
    }

    echo _show_error($exception_message);
    exit;
}

发生未处理异常时会给wecenter发邮件,不需要这个行为可以关闭掉report_diagnostics设置项


国际化和多语言 ←o→ BBCode

你可能感兴趣的:(wecenter学习笔记-全局异常处理)