exception 是否需要php,php – “抛出新异常”是否需要exit()?

不,执行抛出异常后的代码不执行。

在这个代码示例中,我标记了将被执行的代码行(代码流):数字:

try {

throw new Exception("caught for demonstration"); // 1

// code below inside the try{} block is never executed

echo "you won't read this." . PHP_EOL;

} catch (Exception $e) {

// you may want to react on the Exception here

echo "exception caught!" . PHP_EOL; // 2

}

// execution flow continues here, because Exception above has been caught

echo "yay, lets continue!" . PHP_EOL; // 3

throw new Exception("uncaught for demonstration"); // 4, end

// execution flow never reaches this point because of the Exception thrown above

// results in "Fatal Error: uncaught Exception ..."

echo "you won't see me, too" . PHP_EOL;

When an exception is thrown, code following the statement will not be executed, and PHP will attempt to find the first matching catch block. If an exception is not caught, a PHP Fatal Error will be issued with an “Uncaught Exception …” message, unless a handler has been defined with set_exception_handler().

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值