PHP Basics

Error and Exception Handlers

ThrowErrorException

Throws internal errors as exceptions.

If registered as error handler, this handles an internal PHP error by converting it into an \ErrorException. It respects the error_reporting directive by only throwing an exception if the severity of the internal error is the same or higher than the setting.

Usage:

set_error_handler(new ThrowErrorException());

By design user-defined error handlers can't handle errors of severity E_ERROR , E_PARSE , E_CORE_ERROR , E_CORE_WARNING , E_COMPILE_ERROR , E_COMPILE_WARNING and most of E_STRICT .

TriggerExceptionError

Triggers errors for uncaught exceptions.

If registered as exception handler, this catches an uncaught exception and converts it into an internal PHP error of severity E_USER_WARNING , then terminates the script with exit status 255 (just like a fatal error). E_USER_ERROR is not used anymore, because passing it to trigger_error() is deprecated since PHP 8.4.

Usage:

set_exception_handler(new TriggerExceptionError());

Search results