PHP 抛出异常嵌套用法

<?php
try {

    dsss();
} catch (Exception $e) {
    
    echo $e->getMessage();
    // die(); // 终止异常
}
function dsss()
{
    try {
        $num1 = 3;
        $num2 = 0;
        if ($num2 == 0) {
            throw new Exception("11321");
        } else {
            $res = $num1 / $num2;
        }

    } catch (Exception $e) {
        throw $e;
    }
}
?>

 

posted @ 2021-03-31 14:53  newmiracle宇宙  阅读(7)  评论(0编辑  收藏