抛出异常

<?
function checkNum($num){
    if($num>1){
        throw new Exception("异常提示-数字必须小于等于1");
    }
    return true;
}

try{
    checkNum(2);
}catch(Exception $e){
    $e->getMessage();
}

$filename='text.txt';
try{
    if(!file_exists($filename)){
        throw new Exception('文件不存在');
    }
}catch(Exception $e){
    echo $e->getMessage();
}

原文地址:https://www.cnblogs.com/daochong/p/5156230.html