抛出异常

<?php
function checknum($num)
{
if($num >= 2)
{
throw new Exception("must below 2"); //抛出异常
}
echo "ll <br>";
return true;
}
try //触发异常
{
checknum(2);
echo "if you see this ,the num is true";
}
catch(Exception $e) //捕获异常,并创建一个含异常信息的对象
{
echo "message :".$e->getMessage();
}

?>

posted on 2017-02-24 18:37  jiangger  阅读(115)  评论(0编辑  收藏  举报