Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Error Handler

The PHP error handler is a method that manages errors when they arise, instead of the default PHP handler.

The error handler is set with the set_error_handler() function.

The error handler is convenient to translate errors, handle custom levels of errors, or convert errors to exceptions.

There is a separate exception handler.

<?php

    set_error_handler('customErrorHandler');
    
    function customErrorHandler($errno, $errstr, $errfile, $errline, array $errcontext)
    {
        // Handles @ error suppression
        if (error_reporting === 0)
        {
            return false;
        }
    
        throw new Exception($errstr, 0, $errno, $errfile, $errline);
    }

?>

Documentation

See Also