码迷,mamicode.com
首页 > 其他好文 > 详细

错误处理try catch

时间:2015-11-23 18:27:08      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

<?php
function inverse($x) {
if (!$x) {
throw new Exception(‘被除数不能为0‘);
}
if ($x>31) {
throw new Exception(‘月数不能大于31‘);
}
return 1/$x;
}

try
{
echo inverse(5) . "<hr>";
echo inverse(10) . "<hr>";
echo inverse(2) . "<hr>";
echo inverse(0) . "<hr>";
}
catch (Exception $e)
{
echo ‘错误提示: ‘, $e->getMessage(), "<hr>";
}

?>

错误处理try catch

标签:

原文地址:http://www.cnblogs.com/jiufen/p/4988807.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!