Custom Exceptions
Create custom exceptions in PHP that are tailor-made for your program.
We'll cover the following
Defining Custom Exceptions #
PHP provides the functionality to create custom exception handlers. It allows you to give separate exception block for each type of exception.
The class must be an extension of the built-in Exception
class since it is the base class. The custom exception class inherits all the objects, properties and methods, from PHP’s Exception
class. You can also add custom objects to this new extended exception class.
Sample Code for Custom Exceptions #
Following is the example of a custom exception class:
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy