8. Error Handling
Activity 8.1: Improving the User Experience through the Handling System and User-Level Errors
Solution
- Create a file called
factorial.php
. - First, add the exception handler that, in order to log the exceptions to the log file, will create a data stream resource using the
fopen()
function, which is assigned to the static variable,$fh
:$exceptionHandler = function (Throwable $e) { static $fh; if (is_null($fh)) { $fh = fopen(__DIR__ . '/app.log', 'a'); if (!$fh) { echo 'Unable to access the log file.', PHP_EOL; exit(1); } }
- Format the log message and write to the log...