主页
PHP
PHP 异常
tryphp_exceptions_try_catch
运行 ❯
×
更改方向
保存代码
更改主题
<!DOCTYPE html> <html> <body> <?php function divide($x, $y) { if($y == 0) { throw new Exception("Cannot divide by zero."); } return $x / $y; } try { echo divide(5, 0); } catch(Exception $e) { echo 'Error: ' . $e->getMessage(); } echo '<br>Hello'; ?> </body> </html>
无法除以。