Sets a user-defined exception handler function

# set_exception_handler

(PHP 5, PHP 7)

set_exception_handler — Sets a user-defined exception handler function

### Descrierea

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.

### Parametri

`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.

  Precauţie

  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.

### Valorile întoarse

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

### Istoricul schimbărilor

Versiune | Descriere
--- | ---
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.

### Exemple

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";
?>`

### A se vedea și

- restore_exception_handler() - Restores the previously defined exception handler function
- restore_error_handler() - Restabilește funcția precedentă de gestionare a erorilor
- error_reporting() - Stabilește ce erori PHP vor fi raportate
- informație despre tipul callback
- PHP 5 Exceptions