PHP throw Keyword

PHP trait Keyword
PHP switch Keyword

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();
}
?>
PHP trait Keyword
PHP switch Keyword

Stay up-to-date about PHP!

We don’t spam!

en English
X
Scroll to Top