How to handle exceptions in PHP ?
Exceptions in PHP: The exception is the one that describes the error or unexpected behavior of the PHP script. The exception is thrown in many PHP tasks and classes. User-defined tasks and classes can also do differently. The exception is a good way to stop work when it comes to data that it can use.
Throw Exceptions in PHP: The throw statement in PHP allows for a defined function or method to do otherwise. If alternatives are thrown, the following code will not be used. If the exception is not detected, a dangerous error will occur with the message “Uncaught Exception”.
Example 2: The following example demonstrates the use of the PHP try…catch statement to avoid the above scenario.
Exception is Caught! : Unable to divide by 0
Example 3: In the following code, whatever is present in the “finally” statement will be executed regardless of the exception.
Exception is Caught! : Unable to divide by 0........Finally block execution - Process complete.