Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP set_exception_handler() Function

PHP set_exception_handler() Function


PHP Error Reference Manual Complete PHP Error Reference Manual


Definition and Usage

The set_exception_handler() function sets a user-defined exception handler function.

This function is used to create your own exception handling method during runtime.

This function returns the previous exception handler, or NULL on failure.

Syntax

set_exception_handler(exception_function)

Parameters Description
exception_function Required. Specifies the function to be called when an uncaught exception occurs.

This function must be defined before calling set_exception_handler(). The exception handler needs one parameter, the thrown exception object.


Tips and Notes

**Tip:** After this exception handler is called, the script stops executing.


Example

Exception: " , $exception->getMessage(); } set_exception_handler('myException'); throw new Exception('Uncaught Exception occurred'); ?>

The output of the code above is shown below:

Exception:

Uncaught Exception occurred


PHP Error Reference Manual Complete PHP Error Reference Manual