php自定义捕获异常函数

<?php

set_error_handler("callback1");

register_shutdown_function("callback2");

set_exception_handler("callback3");

function callback1($type, $message, $file, $line)
{
    var_dump('<b>set_error_handler: ' . $type . ':' . $message . ' in ' . $file . ' on ' . $line . ' line .</b><br />');
}

function callback2(\Exception $e)
{
    echo '<pre>';
    print_r($e->getMessage());
    echo '</pre>';
}

function callback3()
{
    echo '<pre>';
    print_r(error_get_last());
    echo '</pre>';
    if ($error = error_get_last()) {
        var_dump('<b>register_shutdown_function: Type:' . $error['type'] . ' Msg: ' . $error['message'] . ' in ' . $error['file'] . ' on line ' . $error['line'] . '</b>');
    }
}


?>

 

posted @ 2021-10-25 14:03  程序员小艺  阅读(103)  评论(0编辑  收藏  举报