Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
<?php // Throwable hierarchy: // Throwable (interface) // Error (engine errors) // TypeError // ParseError // ArithmeticError // DivisionByZeroError // ValueError // Exception (application errors) // LogicException // RuntimeException // ... // Catch both Error and Exception with Throwable try { $result = 10 / 0; } catch (DivisionByZeroError $e) { echo "Math error: " . $e->getMessage(); } // Type error try { function strictAdd(int $a, int $b): int { return $a + $b; } strictAdd("not", "numbers"); // TypeError in strict mode } catch (TypeError $e) { echo "Type error: " . $e->getMessage(); }
Result
Open