<?php
#We use exceptions to handle errors in PHP
function divide($dividend, $divisor) {
if($divisor == 0) {
throw new Exception("Division by zero");
}
return $dividend / $divisor;
}
echo divide(5, 0);
?>
<?php
function inverse($x) {
if (!$x) {
throw new Exception('Division durch Null.');
}
return 1/$x;
}
try {
echo inverse(5) . "
";
echo inverse(0) . "
";
} catch (Exception $e) {
echo 'Exception abgefangen: ', $e->getMessage(), "
";
}
// Ausführung fortsetzen
echo "Hallo Welt
";
?>
<?php
function divide($dividend, $divisor) {
if($divisor == 0) {
throw new Exception("Division by zero");
}
return $dividend / $divisor;
}
echo divide(5, 0);
?>