<?php
//test try catch
//先是throw new Exception
//后是try 执行程序 catche 捕捉 throw
//最后$e->getMessage 输出throw的内容
function getNum($num)
{
if($num<5)
{
throw new Exception('num is less than 5');
}
return $num;
}
try{
$num = getNum(2);
echo $num;
}catch(Exception $e)
{
echo $e->getMessage();
}
输出:<pre name="code" class="php">num is less than 5