PHP异常学习, 请指正
时间:2006-07-21 来源:cnscn2008
function Cns_Exception_Handler($code, $string, $file, $line){ throw new Exception($string,$code);}
//设置异常捕获处理函数set_error_handler('Cns_Exception_Handler', E_ALL);
//以try结构执行会出现异常的语句try{ print 2/0; print "This will never be printed";}catch (Exception $e){ print " Exception catched:\n"; print " Code: ".$e->getCode()."\n"; print " Message: ".$e->getMessage()."\n"; print " Line: ".$e->getLine()."\n";}
?>
[root@localhost html]# php a.php
Exception catched:
Code: 2
Message: Division by zero
Line: 16
相关阅读 更多 +