首页 > 代码库 > 抛出异常

抛出异常

<?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();
}

?>

抛出异常