异常处理

<?php
function inverse($x) {
if (!$x) {
throw new Exception(‘Division by zero.’);
}
else return 1/$x;
}

try {
echo inverse(5) . ” “;
echo inverse(0) . ” “;
} catch (Exception $e) {
echo ‘Caught exception: ‘,  $e->getMessage(), ” “;//这里输出异常
}

// Continue execution
echo ‘Hello World’;
?>

未经允许不得转载:肥猫博客 » 异常处理

赞 (0)
分享到: 更多

评论 0