Home > Article > Backend Development > php syntax error capture
PHP syntax error capture processing
Generally, the method used to capture errors is:
try{ ... }catch(Exception $e){ echo $e->getMessage(); }
or
set_exception_handler(function ($exception) { echo $exception->getMessage(); });
Example:
<?php function test(){ throw new Exception('参数错误'); } try{ //如果catch没有捕获到,才会执行到这里 set_exception_handler(function ($exception) { echo $exception;//exception 'Exception' with message '参数错误' in /www/web/...(一堆信息) echo '<br>'; echo $exception->getMessage();//参数错误 }); test(); }catch(Exception $e){ echo $e->getMessage();//参数错误 }
set_exception_handler
— Set a user-defined exception handling function for exceptions that are not caught with try/catch blocks.
Recommended tutorial: PHP video tutorial
The above is the detailed content of php syntax error capture. For more information, please follow other related articles on the PHP Chinese website!