關于return true 問題
//創建可拋出一個異常的函數
function checkNum($number){
? ? if($number>1){
? ? ? ? throw new Exception("異常提示-數字必須小于等于1");
? ? }
? ? return true;
}
//在 "try" 代碼塊中觸發異常
try{
? ? checkNum(2);
? ? //如果異常被拋出,那么下面一行代碼將不會被輸出
? ? echo '如果能看到這個提示,說明你的數字小于等于1';
}catch(Exception $e){
? ? //捕獲異常
? ? echo '捕獲異常: ' .$e->getMessage();
}
如果把加上return true和沒加上有區別么?
2015-01-28
函數需要有返回值。