// 报错, 扑捉不到异常
// try {
//     require ('test_try_catch.php');
// } catch (Exception $e) {
//     echo $e->getMessage();
// }
// 可以扑捉到异常
try {
    if (file_exists('test_try_catch.php')) {
        require ('test_try_catch.php');
        echo 23324444444444444;   //不执行
    } else {
        throw new Exception('文件不存在');
    }
} catch (Exception $e) {
    echo $e->getMessage();
}
echo 232; //执行
php的try catch 能捕捉到的只能是你自己 throw new Exception("");的错误,throw之后的语句会进入到catch中继续执行。
PHP 异常处理
点赞
收藏
 
  
  
  
 
 
  
 
 
 