code 1
<?php
function foo(){
$bar = 1;
try{
throw new Exception('I am Wu Xiancheng.');
}catch(Exception $e){
return $bar;
$bar--; // this line will be ignored
}finally{
$bar++;
}
}
echo foo(); // 2
?>
code 2
<?php
function foo(){
$bar = 1;
try{
throw new Exception('I am Wu Xiancheng.');
}catch(Exception $e){
return $bar;
$bar--; // this line will be ignored
}finally{
$bar++;
return $bar;
}
}
echo foo(); //2
?>
code 3
<?php
function foo(){
$bar = 1;
try{
throw new Exception('I am Wu Xiancheng.');
}catch(Exception $e){
return $bar;
$bar--; // this line will be ignored
}finally{
return 100;
}
}
echo foo(); //100
?>
php try catch finally 结构
PHP异常处理详解
最新推荐文章于 2023-09-16 02:33:45 发布
本文通过三个PHP代码示例详细解析了异常处理机制中try、catch和finally块的执行流程及返回值特点,尤其是在finally块中return语句的影响。

942

被折叠的 条评论
为什么被折叠?



