This article mainly introduces the code for catching exceptions in PHP, which has certain reference value. Now I share it with everyone. Friends in need can refer to it
//创建可抛出一个异常的函数 function checkCash($number){ if($number != 1){ throw new Exception("状态不等于1抛出异常"); } return true; } //在 "try" 代码块中触发异常 try{ //使用0去触发异常 checkCash($ret_arr['status']); } //捕获异常 catch(Exception $e) { newDie('异常捕获'); }
Related recommendations:
[php manual]Exception handling
The above is the detailed content of PHP exception catching code. For more information, please follow other related articles on the PHP Chinese website!