Last active
April 21, 2017 10:48
-
-
Save xuyuji9000/cc40d58930aa4c62c1c8843fceacb3b2 to your computer and use it in GitHub Desktop.
PHP try catch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"; | |
} | |
echo "Hello World.\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment