Use a user-defined function to handle exceptions in PHP

Description

The following code shows how to use a user-defined function to handle exceptions.

Example


 //from  w  w w  .j a v  a 2  s  .co  m
  
<?php
function myException($exception)
{
    echo "<b>Exception:</b> " , $exception->getMessage();
}
    
set_exception_handler('myException');
    
throw new Exception('Uncaught Exception occurred');
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Language Basic »




PHP Introduction
PHP Operators
PHP Statements
Variable
PHP Function Create
Exception
PHP Class Definition