June 2017
Intermediate to advanced
536 pages
9h 49m
English
PHP provides a mechanism in the form of a set_exception_handler function that allows us to define a custom handler function for all uncaught throwables, including exceptions. The set_exception_handler function accepts a single callable parameter--either a function name passed as string, or an entire anonymous function.
Let's take a look at the following function name passed as string example:
<?php function throwableHandler(Throwable $t) { echo 'Throwable Handler: ' . $t->getMessage(); } set_exception_handler('throwableHandler'); echo 'start'; throw new Exception('Ups!'); echo 'end';
Let's take a look at the following anonymous function example:
<?php set_exception_handler(function (Throwable $t) { echo 'Throwable ...Read now
Unlock full access