PHP:try{}catch(){}捕获不到异常??怎回事啊
本文介绍了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();
}
}
解决方案
你的 catch, catch 的错误是spl_autoload_register
是否能注册函数成功
try {
$test = new tests;
$test->show();
} catch (Exception $e) {
echo $e->getMessage();
exit;
}
这样才能有你想要的结果
这篇关于PHP:try{}catch(){}捕获不到异常??怎回事啊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文