YouTip LogoYouTip

Php Error Handling

# PHP 7 Error Handling [![Image 4: PHP 7 New Features](#) PHP 7 New Features](#) PHP 7 changed the way most errors are reported. Unlike the traditional error reporting mechanism in PHP 5, most errors are now thrown as **Error** exceptions. This Error exception can be caught by a try / catch block just like a normal exception. If there is no matching try / catch block, the exception handler function (registered by set_exception_handler()) is called to handle it. If no exception handler function has been registered, it is handled in the traditional way: reported as a fatal error. The Error class is not extended from the Exception class, so code like `catch (Exception $e) { ... }` will not catch an Error. You can use code like `catch (Error $e) { ... }` or register an exception handler function (`set_exception_handler()`) to catch an Error. ### Error Exception Hierarchy * **Error** * **ArithmeticError** * **AssertionError** * **DivisionByZeroError** * **ParseError** * **TypeError** * Exception * ... !(#) ### Example ## Example n % 0; return $value; } catch (DivisionByZeroError $e) { return $e->getMessage(); } } } $mathOperationsObj = new MathOperations(); print($mathOperationsObj->doOperation()); ?> The output of the above program is: Modulo by zero * * PHP 7 New Features](#) [](#)(#) (#)[](#) (javascript:void(0);) * [Python / Data Science](javascript:void(0);) * (
← Php Error HandlingPhp Expectations β†’