1// 报错, 扑捉不到异常 2// try { 3// require ('test_try_catch.php'); 4// } catch (Exception $e) { 5// echo $e->getMessage(); 6// } 7 8 9// 可以扑捉到异常 10try { 11 if (file_exists('test_try_catch.php')) { 12 require ('test_try_catch.php'); 13 echo 23324444444444444; //不执行 14 } else { 15 throw new Exception('文件不存在'); 16 } 17} catch (Exception $e) { 18 echo $e->getMessage(); 19} 20 21echo 232; //执行 22 23 24php的try catch 能捕捉到的只能是你自己 throw new Exception("");的错误,throw之后的语句会进入到catch中继续执行。
PHP 异常处理
Wesley13
2021-10-11
1215 0 0
点赞
收藏
评论区
加载中...