Establish a user-defined function to handle exceptions.
<?php // A user-defined exception handler function function myException($exception) { echo “<b>Exception:</b> “, $exception->getMessage(); } // Set user-defined exception handler function set_exception_handler(“myException”); // Throw exception throw new Exception(“Uncaught exception occurred!”); ?> |
The set_exception_handler() function establishes a user-defined function to handle exceptions.
The script will halt execution after the exception handler is invoked.
set_exception_handler(exceptionhandler); |
Parameter |
Description |
exceptionhandler |
Required. Specifies the name of the function to execute when an uncaught exception occurs. Passing |
Return Value: |
A string containing the previously defined exception handler, or |
PHP Version: |
5.0+ |
PHP Changelog: |
Previously, passing |