Skip to content

Instantly share code, notes, and snippets.

@rafaelmaeuer
Created October 13, 2023 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaelmaeuer/43e16f6382e85b2819291d0af9b74431 to your computer and use it in GitHub Desktop.
Save rafaelmaeuer/43e16f6382e85b2819291d0af9b74431 to your computer and use it in GitHub Desktop.
<?php
function inverse($x) {
if (!$x) {
throw new Exception('Division by zero.');
}
return 1/$x;
}
try {
echo inverse(5) . "\n";
echo inverse(0) . "\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
// Continue execution
echo "Hello World\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment