//创建可抛出一个异常的函数 function checkcash($number){ if($number != 1){ throw new exception("状态不等于1抛出异常"); } return true; } //在 "try" 代码块中触发异常 try{ //使用0去触发异常 checkcash($ret_arr['status']); } //捕获异常 catch(exception $e) { newdie('异常捕获'); }
相关推荐:
【php手册】异常处理
php 7 错误异常级别
以上就是php捕获异常的代码的详细内容。
