PHP中try{}catch{}的具体用法详解

PHP中try{}catch{}是异常处理,将要执行的代码放入TRY块中,如果这些代码执行过程中某一条语句发生异常,则程序直接跳转到CATCH块中由$e收集错误信息和显示。任何调用 可能抛出异常的方法的代码都应该使用try语句,Catch语句用来处理可能抛出的异常。

 < ?php   
 try {   
$mgr = new CommandManager();   
$cmd = $mgr->getCommandObject("realcommand");   
$cmd->execute();   
} catch (Exception $e) {   
print $e->getMessage();   
exit();   
}   
 ?> 

猜你喜欢

转载自blog.csdn.net/qq_33876293/article/details/82865492
今日推荐