为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
慕工程0101907 2019-03-17 01:05:25
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(); } }
查看完整描述

1 回答

?
犯罪嫌疑人X

TA贡献2080条经验 获得超4个赞

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

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

这样才能有你想要的结果

查看完整回答
反对 回复 2019-03-18
  • 1 回答
  • 0 关注
  • 1457 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信