PHP 使用try catch,捕获异常

<?php 
    header('Content-type:text/html;charset=utf-8');
    $a 1;
    $b 2;
    try {
        //结果为真,设置异常信息
        if$a $b )
        {
            throw new Exception('a要大于b');
        }
    } catch (Exception $err{
        // 返回异常信息
        echo $err->getMessage();
    }
?>

posted @ 2017-08-09 23:37  shaoguan  阅读(2091)  评论(0编辑  收藏  举报