X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR BOOTSTRAP XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

PHP set_exception_handler() Function

PHP Error PHP Error Reference

Example

Set a user-defined exception handler function:

<?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 above code will output something like this:

Exception: Uncaught exception occurred!


Definition and Usage

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

The script will stop executing after the exception handler is called. 


Syntax

set_exception_handler(exceptionhandler);

Parameter Description
exceptionhandler Required. Specifies the name of the function to be run when an uncaught exception occurs. NULL can be passed instead, to reset this handler to its default state

Technical Details

Return Value: A string that contains the previously defined exception handler, or NULL on error or if no previous handler was defined
PHP Version: 5.0+
PHP Changelog: Previously, if NULL was passed then this function returned TRUE. It returns the previous handler since PHP 5.5


PHP Error PHP Error Reference

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook