Current Location: Home> Function Categories> set_exception_handler

set_exception_handler

Set user-defined exception handling functions
Name:set_exception_handler
Category:Error handling
Programming Language:php
One-line Description:Set user-defined exception handling functions.

Definition and usage

set_exception_handler() function sets a user-defined exception handling function.

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

Example

Set user-defined exception handling functions:

 <?php
// User-defined exception handling function
 function myException ( $exception ) {
     echo "<b>Exception:</b> " , $exception -> getMessage ( ) ;
 }

 // Set user-defined exception handling function
 set_exception_handler ( "myException" ) ;

// throw an exception
throw new Exception ( "Uncaught exception occurred!" ) ;
 ?> 

The output of the above code is similar to this:

 Exception: Uncaught exception occurred!
Similar Functions
Popular Articles