Example of PHP Exception - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of Example of PHP Exception.php
- <?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";
File Description
- Example of PHP Exception
- PHP Code
- 08 Aug-2018
- 309 Bytes
You can Share it:
Latest PHP Pastes