PHP program to create a user-defined exception class

bookmark

<?php
// PHP program to demonstrate the user-defined exception.
class UserException extends Exception
{
}

try
{
    $exp = new UserException("User defined exception");
    throw $exp;
}
catch(UserException $e)
{
    printf("Exception: %s", $e->getMessage());
}
?>


Output
Exception: User defined exception