PHP:try{}catch(){}捕获不到异常??怎回事啊

if(function_exists('spl_autoload_register')){
    try {
        spl_autoload_register(function ($name) {
            if(file_exists($name.'.php')){
                require_once $name.'.php';
            }else{
                throw new Exception('undefined this');
            }
        });

    }catch (Exception $e){
        echo $e->getMessage();
        exit;
    }
}

class main{
    public function myf(){
        $test = new tests;
        $test->show();
    }
}
阅读 8.5k
1 个回答

你的 catch, catch 的错误是spl_autoload_register 是否能注册函数成功

try {
    $test = new tests;
    $test->show();
} catch (Exception $e) {
    echo $e->getMessage();
    exit;
}

这样才能有你想要的结果

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题