No cache version.

Caching disabled. Default setting for this page:enabled (code LNG204)
If the display is too slow, you can disable the user mode to view the cached version.

Rechercher une fonction PHP

set_exception_handler

(PHP 5, PHP 7)

set_exception_handler Sets a user-defined exception handler function

Description

set_exception_handler ( callable $exception_handler ) : callable

Sets the default exception handler if an exception is not caught within a try/catch block. Execution will stop after the exception_handler is called.

PHP: set_exception_handler - Manual Home of Manuel PHP  Contents Haut

Parameters

exception_handler

Name of the function to be called when an uncaught exception occurs. This handler function needs to accept one parameter, which will be the exception object that was thrown. This is the handler signature before PHP 7:

handler ( Exception $ex ) : void

Since PHP 7, most errors are reported by throwing Error exceptions, which will be caught by the handler as well. Both Error and Exception implements the Throwable interface. This is the handler signature since PHP 7:

handler ( Throwable $ex ) : void

NULL may be passed instead, to reset this handler to its default state.

Caution

Note that providing an explicit Exception type hint for the ex parameter in your callback will cause issues with the changed exception hierarchy in PHP 7.

PHP: set_exception_handler - Manual Home of Manuel PHP  Contents Haut

Return Values

Returns the name of the previously defined exception handler, or NULL on error. If no previous handler was defined, NULL is also returned.

PHP: set_exception_handler - Manual Home of Manuel PHP  Contents Haut

Changelog

Version Description
7.0.0 The type of parameter passed into exception_handler changed from Exception to Throwable
5.5.0 Previously, if NULL was passed then this function returned TRUE. It returns the previous handler since PHP 5.5.0.

PHP: set_exception_handler - Manual Home of Manuel PHP  Contents Haut

Examples

Example #1 set_exception_handler() example

<?php
function exception_handler($exception) {
  echo 
"Uncaught exception: " $exception->getMessage(), "\n";
}

set_exception_handler('exception_handler');

throw new 
Exception('Uncaught Exception');
echo 
"Not Executed\n";
?>

PHP: set_exception_handler - Manual Home of Manuel PHP  Contents Haut

See Also

Find a PHP function

English translation

You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.

If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.

Thank you in advance.

Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-function.set-exception-handler.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.

References

  1. View the html document Language of the document:fr Manuel PHP : http://php.net

These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.

Contents Haut