In this article, you will learn how to throw exception in PHP. The throw keyword in PHP is used to throw exceptions. Exceptions are a way to change the program flow if an unexpected situation arises, such as invalid data.
examples of the THROW function
Example 1. In this example, we throw an exception.
<?php
try {
throw new Exception("This is an exception");
} catch(Exception $e) {
echo $e->getMessage();
}
?>